narsil/Tanshu.Accounts.Repository/Fluent/EnumConvention.cs
unknown 59909a5ee7 Updated NH, Code Refactoring, made all DB transactions atomic.
Must use the Repositories with Using or else bad things will happen.
2011-06-30 01:57:07 +05:30

27 lines
986 B
C#

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);
}
}
}