Harald Wolff 2019-11-24 14:54:40 +01:00
commit a68417527d
1 changed files with 12 additions and 1 deletions

View File

@ -19,6 +19,9 @@ namespace ln.types.odb.ng.mappings
List<FieldInfo> mappedFields = new List<FieldInfo>();
Func<Mapper, Document, object> createObjectHook;
Func<FieldInfo, bool> filterFieldsHook;
public ClassMapping(Type type)
{
Logging.Log(LogLevel.DEBUG, "Constructing ClassMapping for {0}",type);
@ -27,10 +30,18 @@ namespace ln.types.odb.ng.mappings
AddFields(type);
}
public ClassMapping(Type type, Func<Mapper, Document, object> createObjectHook, Func<FieldInfo, bool> filterFieldsHook)
:this(type)
{
this.createObjectHook = createObjectHook;
this.filterFieldsHook = filterFieldsHook;
}
private void AddFields(Type type)
{
foreach (FieldInfo fieldinfo in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
{
if ((filterFieldsHook == null) || filterFieldsHook(fieldinfo))
mappedFields.Add(fieldinfo);
}
@ -56,7 +67,7 @@ namespace ln.types.odb.ng.mappings
return o;
}
return Activator.CreateInstance(MappedType, true);
return (createObjectHook != null) ? createObjectHook(mapper,document) : Activator.CreateInstance(MappedType, true);
}
public object UnmapValue(Mapper mapper,ODBEntity oval)