comparison Source/Mapping/Fluent/FluentMapHelper.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using BLToolkit.Reflection.Extension;
2
3 namespace BLToolkit.Mapping.Fluent
4 {
5 public static class FluentMapHelper
6 {
7 public static void MergeExtensions(ExtensionList fromExt, ref ExtensionList toExt)
8 {
9 foreach (var kv in fromExt)
10 {
11 TypeExtension toType;
12 if (toExt.TryGetValue(kv.Key, out toType))
13 {
14 MergeExtensions(kv.Value, ref toType);
15 }
16 else
17 {
18 toExt.Add(kv.Key, kv.Value);
19 }
20 }
21 }
22
23 public static void MergeExtensions(TypeExtension fromExt, ref TypeExtension toExt)
24 {
25 if (ReferenceEquals(fromExt, toExt))
26 {
27 return;
28 }
29 foreach (var attribute in fromExt.Attributes)
30 {
31 AttributeExtensionCollection attrs;
32 if (toExt.Attributes.TryGetValue(attribute.Key, out attrs))
33 {
34 MergeExtensions(attribute.Value, ref attrs);
35 }
36 else
37 {
38 toExt.Attributes.Add(attribute.Key, attribute.Value);
39 }
40 }
41 foreach (var member in fromExt.Members)
42 {
43 MemberExtension value;
44 if (toExt.Members.TryGetValue(member.Key, out value))
45 {
46 MergeExtensions(member.Value, ref value);
47 }
48 else
49 {
50 toExt.Members.Add(member.Key, member.Value);
51 }
52 }
53 }
54
55 private static void MergeExtensions(MemberExtension fromExt, ref MemberExtension toExt)
56 {
57 foreach (var attribute in fromExt.Attributes)
58 {
59 if (toExt.Attributes.ContainsKey(attribute.Key))
60 {
61 toExt.Attributes.Remove(attribute.Key);
62 }
63 toExt.Attributes.Add(attribute.Key, attribute.Value);
64 }
65 }
66
67 private static void MergeExtensions(AttributeExtensionCollection fromExt, ref AttributeExtensionCollection toExt)
68 {
69 toExt.AddRange(fromExt);
70 }
71 }
72 }