Add Hooks (createObjectHook,filterFieldsHook) to ClassMapping
parent
ad9157a0ca
commit
43a39cb7e4
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue