Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
public class EnumerationTypeConvention : IPropertyConvention, IPropertyConventionAcceptance
private static readonly Type OpenType = typeof(EnumerationType<>);
public void Apply(IPropertyInstance instance)
var closedType = OpenType.MakeGenericType(instance.Property.PropertyType);
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
criteria.Expect(x => IsEnumerationType(x.Property.PropertyType));
private bool IsEnumerationType(Type type)
return GetTypeHierarchy(type)
.Where(t => t.IsGenericType)
.Select(t => t.GetGenericTypeDefinition())
.Any(t => t == typeof(Enumeration<>));
private IEnumerable<Type> GetTypeHierarchy(Type type)
while (type != null)
yield return type;
type = type.BaseType;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.