narsil/Tanshu.Accounts.Repository/Fluent/EnumConvention.cs

27 lines
986 B
C#
Raw Normal View History

using System;
using FluentNHibernate.Conventions;
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<IPropertyInspector> 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);
}
}
}