I want to use map mechanism, based on property attribute marking, like this:
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public class DomainSignatureAttribute : Attribute { }
public class SomeThing {
[DomainSignature]
public virtual string SomePropertyForMapping {get;set;}
[DomainSignature]
public virtual int OtherPropertyForMapping {get;set;}
public virtual string OtherPropertyWithoutMapping {get;}
}
So in ClassMap children I want to realise this method, that map all properties, marked by DomainSignatureAttribute attribute:
protected void MapPropertiesWithStandartType()
{
foreach (PropertyInfo property in typeof(T).GetProperties())
{
if (property != null)
{
object[] domainAttrs = property.GetCustomAttributes(typeof (DomainSignatureAttribute), true);
if (domainAttrs.Length > 0)
Map(x => property.GetValue(x, null));
}
}
}
But there is a small problem with Linq. When FluentNHibernate builds mapping (Cfg.BuildSessionFactory()) it break with
Tried to add property 'GetValue' when already added.
exception. As I undestand I need to rebuild Linq expression: x => property.GetValue(x, null)
into correct form.
Please don't suggest to use AutoMap feature and don't suggest to use manual mapping.