Mercurial > pub > bltoolkit
comparison Source/Common/EntityBase.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; | |
3 using System.ComponentModel; | |
4 using System.Runtime.InteropServices; | |
5 | |
6 using BLToolkit.ComponentModel; | |
7 using BLToolkit.Mapping; | |
8 using BLToolkit.Validation; | |
9 | |
10 namespace BLToolkit.Common | |
11 { | |
12 [Serializable, Trimmable, ComVisible(true), JetBrains.Annotations.UsedImplicitly] | |
13 public abstract class EntityBase : ICustomTypeDescriptor | |
14 { | |
15 #region Protected members | |
16 | |
17 protected virtual ICustomTypeDescriptor CreateTypeDescriptor() | |
18 { | |
19 return new CustomTypeDescriptorImpl(GetType()); | |
20 } | |
21 | |
22 #endregion | |
23 | |
24 #region ICustomTypeDescriptor Members | |
25 | |
26 private static readonly Hashtable _hashDescriptors = new Hashtable(); | |
27 | |
28 [NonSerialized] | |
29 private ICustomTypeDescriptor _typeDescriptor; | |
30 private ICustomTypeDescriptor TypeDescriptor | |
31 { | |
32 get | |
33 { | |
34 if (_typeDescriptor == null) | |
35 { | |
36 Type key = GetType(); | |
37 | |
38 _typeDescriptor = (ICustomTypeDescriptor)_hashDescriptors[key]; | |
39 | |
40 if (_typeDescriptor == null) | |
41 _hashDescriptors[key] = _typeDescriptor = CreateTypeDescriptor(); | |
42 } | |
43 | |
44 return _typeDescriptor; | |
45 } | |
46 } | |
47 | |
48 AttributeCollection ICustomTypeDescriptor.GetAttributes() | |
49 { | |
50 return TypeDescriptor.GetAttributes(); | |
51 } | |
52 | |
53 string ICustomTypeDescriptor.GetClassName() | |
54 { | |
55 return TypeDescriptor.GetClassName(); | |
56 } | |
57 | |
58 string ICustomTypeDescriptor.GetComponentName() | |
59 { | |
60 return TypeDescriptor.GetComponentName(); | |
61 } | |
62 | |
63 TypeConverter ICustomTypeDescriptor.GetConverter() | |
64 { | |
65 return TypeDescriptor.GetConverter(); | |
66 } | |
67 | |
68 EventDescriptor ICustomTypeDescriptor.GetDefaultEvent() | |
69 { | |
70 return TypeDescriptor.GetDefaultEvent(); | |
71 } | |
72 | |
73 PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() | |
74 { | |
75 return TypeDescriptor.GetDefaultProperty(); | |
76 } | |
77 | |
78 object ICustomTypeDescriptor.GetEditor(Type editorBaseType) | |
79 { | |
80 return TypeDescriptor.GetEditor(editorBaseType); | |
81 } | |
82 | |
83 EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes) | |
84 { | |
85 return TypeDescriptor.GetEvents(attributes); | |
86 } | |
87 | |
88 EventDescriptorCollection ICustomTypeDescriptor.GetEvents() | |
89 { | |
90 return TypeDescriptor.GetEvents(); | |
91 } | |
92 | |
93 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes) | |
94 { | |
95 return TypeDescriptor.GetProperties(attributes); | |
96 } | |
97 | |
98 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() | |
99 { | |
100 return TypeDescriptor.GetProperties(); | |
101 } | |
102 | |
103 object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd) | |
104 { | |
105 // Do not relay this call to TypeDescriptor. We are the owner. | |
106 // | |
107 return this; | |
108 } | |
109 | |
110 #endregion | |
111 | |
112 #region Validation | |
113 | |
114 public virtual void Validate() | |
115 { | |
116 Validator.Validate(this); | |
117 } | |
118 | |
119 public virtual bool IsValid(string fieldName) | |
120 { | |
121 return Validator.IsValid(this, fieldName); | |
122 } | |
123 | |
124 public virtual string[] GetErrorMessages(string fieldName) | |
125 { | |
126 return Validator.GetErrorMessages(this, fieldName); | |
127 } | |
128 | |
129 #endregion | |
130 } | |
131 } |