Mercurial > pub > bltoolkit
comparison Source/Mapping/MapMemberInfo.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 System; | |
2 using System.Collections.Generic; | |
3 using System.Data; | |
4 using System.Diagnostics; | |
5 | |
6 using BLToolkit.DataAccess; | |
7 using BLToolkit.Reflection; | |
8 using BLToolkit.Reflection.Extension; | |
9 | |
10 namespace BLToolkit.Mapping | |
11 { | |
12 [DebuggerStepThrough] | |
13 public class MapMemberInfo | |
14 { | |
15 public MapMemberInfo() | |
16 { | |
17 DbType = DbType.Object; | |
18 } | |
19 | |
20 public MemberAccessor MemberAccessor { get; set; } | |
21 public MemberAccessor ComplexMemberAccessor { get; set; } | |
22 public string Name { get; set; } | |
23 public string MemberName { get; set; } | |
24 public string Storage { get; set; } | |
25 public bool IsInheritanceDiscriminator { get; set; } | |
26 public bool Trimmable { get; set; } | |
27 public bool SqlIgnore { get; set; } | |
28 public bool Nullable { get; set; } | |
29 public object NullValue { get; set; } | |
30 public object DefaultValue { get; set; } | |
31 public Type Type { get; set; } | |
32 public int DbSize { get; set; } | |
33 public bool IsDbTypeSet { get; set; } | |
34 public bool IsDbSizeSet { get; set; } | |
35 public MappingSchema MappingSchema { get; set; } | |
36 public MemberExtension MemberExtension { get; set; } | |
37 public DbType DbType { get; set; } | |
38 public KeyGenerator KeyGenerator { get; set; } | |
39 | |
40 private MapValue[] _mapValues; | |
41 public MapValue[] MapValues | |
42 { | |
43 get { return _mapValues; } | |
44 set | |
45 { | |
46 _mapValues = value; | |
47 if (value != null) | |
48 CacheMapValues(); | |
49 else | |
50 { | |
51 _mapValueCache = new Dictionary<object, object>(); | |
52 _origValueCache = new Dictionary<object, object>(); | |
53 } | |
54 } | |
55 } | |
56 | |
57 private Dictionary<object,object> _mapValueCache; | |
58 | |
59 public bool TryGetOrigValue(object mapedValue, out object origValue) | |
60 { | |
61 return _mapValueCache.TryGetValue(mapedValue, out origValue); | |
62 } | |
63 | |
64 private Dictionary<object,object> _origValueCache; | |
65 | |
66 public bool TryGetMapValue(object origValue, out object mapValue) | |
67 { | |
68 return _origValueCache.TryGetValue(origValue, out mapValue); | |
69 } | |
70 | |
71 private void CacheMapValues() | |
72 { | |
73 _mapValueCache = new Dictionary<object,object>(); | |
74 | |
75 foreach (var mv in MapValues) | |
76 foreach (var mapValue in mv.MapValues) | |
77 { | |
78 _mapValueCache[mapValue] = mv.OrigValue; | |
79 | |
80 // this fixes spesial case for char | |
81 if (mapValue is char) | |
82 { | |
83 var str = new string(new[] { (char)mapValue }); | |
84 _mapValueCache[str] = mv.OrigValue; | |
85 } | |
86 } | |
87 | |
88 _origValueCache = new Dictionary<object, object>(); | |
89 | |
90 foreach (var mv in MapValues) | |
91 { | |
92 // previous behaviour - first wins! | |
93 // yah, no... | |
94 // any wins - attributes order is not specified | |
95 // and memberInfo.GetCustomAttributes(...) order and can differ | |
96 if (!_origValueCache.ContainsKey(mv.OrigValue)) | |
97 _origValueCache[mv.OrigValue] = mv.MapValues[0]; | |
98 } | |
99 } | |
100 } | |
101 } |