narsil/Tanshu.Accounts.Repository/Fluent/PropertyAccessConvention.cs
unknown 831ec37cda Reprint and Printed bill editing logged.
Printed bill can no longer be changed, any changes voids the bill and prints a new one.
Added option to Split Bill.
Kot printed with right time.
Numerous bug fixes.
2011-08-23 12:40:05 +05:30

37 lines
1.2 KiB
C#

using System;
using System.Reflection;
using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.Inspections;
using FluentNHibernate.Conventions.Instances;
namespace Tanshu.Accounts.Conventions
{
public class PropertyAccessConvention : IPropertyConvention
{
public void Apply(IPropertyInstance instance)
{
var entityType = instance.EntityType;
var camelCaseUnderscoreName = ConvertToCamelCaseUnderscore(instance.Name);
// Default is to use property setter, so only modify mapping
// if there is a backing field
if (HasField(entityType, camelCaseUnderscoreName))
instance.Access.CamelCaseField(CamelCasePrefix.Underscore);
}
private static string ConvertToCamelCaseUnderscore(string propertyName)
{
return "_" + propertyName[0].ToString().ToLower() + propertyName.Substring(1);
}
private static bool HasField(Type type, string fieldName)
{
var backingField = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
return backingField != null;
}
}
}