Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Created March 18, 2010 23:13
Show Gist options
  • Save jfromaniello/337035 to your computer and use it in GitHub Desktop.
Save jfromaniello/337035 to your computer and use it in GitHub Desktop.
//A way to map WellKnownInstaceType ( http://fabiomaulo.blogspot.com/2009/08/from-db-to-ram-wellknowinstancetype.html )
//artifact
public class WellKnownInstancePattern<TType, TWellKnownInstanceType>
: IPatternApplier<MemberInfo, IPropertyMapper>
where TWellKnownInstanceType : WellKnownInstanceType<TType>
where TType : class
{
public bool Match(MemberInfo subject)
{
return subject.GetPropertyOrFieldType().Equals(typeof (TType));
}
public void Apply(MemberInfo subject, IPropertyMapper applyTo)
{
applyTo.Type<TWellKnownInstanceType>();
}
}
//usage
public void RegisterPatterns(Mapper mapper)
{
mapper.PatternsAppliers.Property.Add(new WellKnownInstancePattern<Country, CountryType>());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment