Mercurial > pub > bltoolkit
view Source/Mapping/Fluent/FluentMapHelper.cs @ 9:1e85f66cf767 default tip
update bltoolkit
author | nickolay |
---|---|
date | Thu, 05 Apr 2018 20:53:26 +0300 |
parents | f990fcb411a9 |
children |
line wrap: on
line source
using BLToolkit.Reflection.Extension; namespace BLToolkit.Mapping.Fluent { public static class FluentMapHelper { public static void MergeExtensions(ExtensionList fromExt, ref ExtensionList toExt) { foreach (var kv in fromExt) { TypeExtension toType; if (toExt.TryGetValue(kv.Key, out toType)) { MergeExtensions(kv.Value, ref toType); } else { toExt.Add(kv.Key, kv.Value); } } } public static void MergeExtensions(TypeExtension fromExt, ref TypeExtension toExt) { if (ReferenceEquals(fromExt, toExt)) { return; } foreach (var attribute in fromExt.Attributes) { AttributeExtensionCollection attrs; if (toExt.Attributes.TryGetValue(attribute.Key, out attrs)) { MergeExtensions(attribute.Value, ref attrs); } else { toExt.Attributes.Add(attribute.Key, attribute.Value); } } foreach (var member in fromExt.Members) { MemberExtension value; if (toExt.Members.TryGetValue(member.Key, out value)) { MergeExtensions(member.Value, ref value); } else { toExt.Members.Add(member.Key, member.Value); } } } private static void MergeExtensions(MemberExtension fromExt, ref MemberExtension toExt) { foreach (var attribute in fromExt.Attributes) { if (toExt.Attributes.ContainsKey(attribute.Key)) { toExt.Attributes.Remove(attribute.Key); } toExt.Attributes.Add(attribute.Key, attribute.Value); } } private static void MergeExtensions(AttributeExtensionCollection fromExt, ref AttributeExtensionCollection toExt) { toExt.AddRange(fromExt); } } }