From 43a39cb7e434812262dd30ccb11d59f536ad7116 Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Tue, 19 Nov 2019 11:39:12 +0100 Subject: [PATCH] Add Hooks (createObjectHook,filterFieldsHook) to ClassMapping --- odb/ng/mappings/ClassMapping.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/odb/ng/mappings/ClassMapping.cs b/odb/ng/mappings/ClassMapping.cs index d7f46d6..aaee28d 100644 --- a/odb/ng/mappings/ClassMapping.cs +++ b/odb/ng/mappings/ClassMapping.cs @@ -19,6 +19,9 @@ namespace ln.types.odb.ng.mappings List mappedFields = new List(); + Func createObjectHook; + Func 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 createObjectHook, Func 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)