using System; using FluentNHibernate.Conventions; using System.Reflection; using FluentNHibernate; using FluentNHibernate.Conventions.Instances; using FluentNHibernate.Conventions.Inspections; using FluentNHibernate.Conventions.AcceptanceCriteria; using System.Diagnostics; namespace Tanshu.Accounts.Conventions { public class EnumConvention : IUserTypeConvention { public void Accept(IAcceptanceCriteria criteria) { criteria.Expect(x => (x.Property.PropertyType.IsEnum || (x.Property.PropertyType.IsGenericType && x.Property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) && x.Property.PropertyType.GetGenericArguments()[0].IsEnum))); } public void Apply(IPropertyInstance target) { Trace.TraceInformation(string.Format("Custom Enum for {0}.{1}", target.EntityType.Name, target.Property.Name)); target.CustomType(target.Property.PropertyType); } } }