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

55 lines
1.7 KiB
C#

using System;
using FluentNHibernate.Conventions;
using System.Reflection;
using FluentNHibernate;
using FluentNHibernate.Conventions.Instances;
using FluentNHibernate.Conventions.Inspections;
using FluentNHibernate.Conventions.AcceptanceCriteria;
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)));
//criteria.Expect(x => x.Property.PropertyType.IsEnum);
}
public void Apply(IPropertyInstance target)
{
target.CustomType(target.Property.PropertyType);
}
}
//public class EnumConvention : IPropertyConvention, IPropertyConventionAcceptance
//{
// #region IPropertyConvention Members
// public void Apply(IPropertyInstance instance)
// {
// instance.CustomType(instance.Property.PropertyType);
// }
// #endregion
// #region IPropertyConventionAcceptance Members
// 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)
// );
// }
// #endregion
//}
}