Thursday, June 23, 2011

Cleaning up POSTs in ASP.NET MVC | Jimmy Bogard's Blog

Cleaning up POSTs in ASP.NET MVC | Jimmy Bogard's Blog:

"What we see over and over and over again is a similar pattern of:

public ActionResult Edit(SomeEditModel form)
    if (IsNotValid)
        return ShowAView(form);


    return RedirectToSuccessPage();

Where all the things in red are things that change from POST action to POST action."

Friday, June 10, 2011

How to replace all automatic properties of string type with a string type which is never null

I have to do this in a piece of code, so I'm recording this here for my future reference.

In Visual Studio's Find and Replace dialog, type the following in the "Find what:" field:
public string \{:i\} \{ get; set; \}

Type this into the "Replace with" field:
private string _\1;\npublic string \1 \{\nget \{ return _\1 ?? ""; \}\nset \{ _\1 = value; \}\n\}

This pattern of performing a test in the getter versus the setter guarantees that it will never be null, and is the pattern used in the TextBox web control's Text property.

Afterwards you'll want to reformat the code, and possibly rename the backing fields, e.g. _FirstName, to be more camel-cased instead of being Pascal-cased(-like), e.g. _firstName instead of _FirstName.

Thursday, June 09, 2011

3 Free E-Books and a Tutorial on Erlang

From ReadWriteWeb: 3 Free E-Books and a Tutorial on Erlang

Date & Time Formats on the Web

Everything you've always wanted to know about date/time formats but were afraid to ask.

Date & Time Formats on the Web: "There are several different formats used in different places in the technologies of the World Wide Web to represent dates, times and date/time combinations (hereafter collectively referred to as “datetimes” unless a distinction has to be made). This document presents a survey of the most significant, details which formats are mandated by the key technologies of the web, and offers advice for deciding what formats you should use in your own web applications."