A colleague of mine and I were discussing good verb replacements for “GetOrCreate” data retrieval patterns, where the “Create” part is responsible for the instantiation of a new instance of something. While the pattern I present here did not solve his particular problem, its at least worth sharing. Its obvious, and probably in use commonly already, but I figure its worth noting.
Essentially the goal is to get away from a “GetOrCreate” master method call and just have two methods: Get(args) and Get(args, Foo default) and then leave the responsibility of default generation up to Foo. This way there’s no unintended side effects and you don’t have to explicitly coalesce (though with this pattern you could as easily coalesce; strictly speaking it isn’t as “discoverable”)…
var foo = FooService.Get(23) ?? new Foo { ... };
So here’s the pattern defined in code:
public class Foo : ICloneable
{
private readonly static Foo __default =
new Foo { Bar = "...", Baz = Int32.MinValue };
public string Bar { get; set; }
public int Baz { get; set; }
public static Foo Default()
{
return (Foo)__default.Clone();
}
public object Clone()
{
return new Foo { Bar = this.Bar, Baz = this.Baz };
}
}
public class FooService
{
public Foo Get(int baz)
{
// retrieve from data store...
return null;
}
public Foo Get(int baz, Func<Foo> @default)
{
return Get(baz) ?? @default.Invoke();
}
}
You’ll see that any associated overhead with Clone only occurs if Get(baz) returns null. I have specifically stepped around the common naming standard of “GetDefault()” for the function – its named like a property - because its intended usage is as follows:
var foo = new FooService().Get(12, Foo.Default);
An ICloneable reference type is pretty much required, though any immutable reference type could get by without cloning because any changes gives you a new copy of that type.
Some Khorne Berzerkers I finished up after having them assembled and sitting in a box for over six years. Also trying out my new camera and figuring out how to take pictures.

Just making sure this is correct. By this I mean PreCode (requires Windows Live Writer 2009) with SyntaxHighligher setup. PreCode is also a stand alone program.
public bool Validate(IValidationDictionary modelState, string prefix)
{
// xVal example code
var dataAnnotationErrors = from prop in TypeDescriptor.GetProperties(_entity).Cast<PropertyDescriptor>()
from attribute in prop.Attributes.OfType<ValidationAttribute>()
where !attribute.IsValid(prop.GetValue(_entity))
select new ErrorInfo(prop.Name, attribute.FormatErrorMessage(string.Empty), _entity);
var brokenRules = GetBrokenRules();
if (!String.IsNullOrEmpty(prefix))
prefix += ".";
if (dataAnnotationErrors.Any())
dataAnnotationErrors.ForEach(ei => modelState.AddError(prefix + ei.PropertyName, ei.ErrorMessage));
if (brokenRules.Any())
brokenRules.ForEach(rule => modelState.AddError(prefix + rule.Property, rule.Message));
return modelState.IsValid;
}
There is a “Fix Indentation” button in PreCode. I am in love.
Now just to setup the clipboard SWF thing.
I should seriously consider a theme with a wider content area.
I've had this machine, dubbed "The BEAST" to the outside world (aka my friends) since last August with literally nothing to do. Its a monster, eight cores, HyperV with several VMs running, 8 GBs of RAM and Server 2008 64-bit. I just wish I had some useful task to put it towards!

Since you can run classic web forms along side MVC its useful to know how to update your *.csproj project file so Visual Studio shows you the MVC items you can add to your project when you add a new item. To do this, after installing MVC (and .NET 3.5 SP1 if you haven't yet):
- Unload your project through Solution Explorer (right-click, unload)
- Edit your *.csproj (yes you can do this in Visual Studio, right click the unloaded project node in Solution Explorer, Edit *.proj)
- In the <ProjectTypeGuids /> node add the GUID {603c0e0b-db56-11dc-be95-000d561079b0}; (the semi-colon is important if you prepend it to the exiting list, which is what I did)
- Add <MvcBuildViews>false</MvcBuildViews> as a sibling of the <ProjectTypeGuids /> node
- Reload the project