If you like to use Business Primitives then you should really enjoy this feature in FubuMvc
namespace fluent.Web.Converters
{
using System.Reflection;
using Domain.MicroTypes;
using FubuCore;
using FubuCore.Binding;
public class HexColorConverterFamily :
IConverterFamily
{
public bool Matches(PropertyInfo property)
{
return property.PropertyType.IsTypeOrNullableOf<HexColor>();
}
public ValueConverter Build(IValueConverterRegistry registry, PropertyInfo property)
{
return context => new HexColor((string) context.PropertyValue);
}
}
}
Now you can use the HexColor type on your view model and this code will automatically do the conversion for you.
Here is how you register it in your FubuRegistry
//in your FubuRegistry
Models
.ConvertUsing<HexColorConverterFamily>();