Datei: NDOEnhancer/Enhancer/Nodes/FieldNode.cs
Last Commit (c39bd40)
1 | // |
2 | // Copyright (c) 2002-2016 Mirko Matytschak |
3 | // (www.netdataobjects.de) |
4 | // |
5 | // Author: Mirko Matytschak |
6 | // |
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
11 | // conditions: |
12 | |
13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
14 | // of the Software. |
15 | // |
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. |
21 | |
22 | |
23 | using System; |
24 | using System.Reflection; |
25 | using System.Collections; |
26 | using NDO; |
27 | using NDO.Mapping.Attributes; |
28 | |
29 | namespace NDOEnhancer |
30 | { |
31 | ····/// <summary> |
32 | ····/// Zusammenfassung für FieldNode. |
33 | ····/// </summary> |
34 | ····internal class FieldNode |
35 | ····{ |
36 | ········string dataType; |
37 | ········string name; |
38 | ········IList fields = new ArrayList(); |
39 | ········bool isEnum; |
40 | ········Type fieldType; |
41 | ········string declaringType; |
42 | ········bool isProperty; |
43 | ········public bool IsProperty |
44 | ········{ |
45 | ············get { return isProperty; } |
46 | ········} |
47 | |
48 | ········ColumnAttribute columnAttribute; |
49 | public ColumnAttribute ColumnAttribute |
50 | { |
51 | get { return columnAttribute; } |
52 | } |
53 | |
54 | ········public FieldNode(MemberInfo mi) |
55 | ········{········ |
56 | ············this.isProperty = (mi is PropertyInfo); |
57 | ············ |
58 | ············this.fieldType = isProperty ? ((PropertyInfo)mi).PropertyType : ((FieldInfo)mi).FieldType; |
59 | ············this.name = mi.Name; |
60 | #pragma warning disable 0618 |
61 | ············if (!isProperty) |
62 | ················this.isOid = mi.GetCustomAttributes(typeof(NDOObjectIdAttribute), false).Length > 0; |
63 | #pragma warning restore 0618 |
64 | ············this.dataType = new ReflectedType(this.fieldType).ILName; |
65 | ············if (!isProperty) |
66 | ············{ |
67 | ················if (mi.DeclaringType != mi.ReflectedType) |
68 | ····················this.declaringType = new ReflectedType(mi.DeclaringType).ILName; |
69 | ············} |
70 | ············this.isEnum = this.fieldType.IsEnum; |
71 | |
72 | ············object[] attrs = mi.GetCustomAttributes(typeof(ColumnAttribute), true); |
73 | ············if (attrs.Length > 0) // since ColumnAttribute.AllowMultiple == false, we can only have max 1 attr. |
74 | ················this.columnAttribute = (ColumnAttribute)attrs[0]; |
75 | ········} |
76 | |
77 | ········public Type FieldType |
78 | ········{ |
79 | ············get |
80 | ············{ |
81 | ················return fieldType; |
82 | ············} |
83 | ········} |
84 | |
85 | ········public bool IsEnum |
86 | ········{ |
87 | ············get { return isEnum; } |
88 | ········} |
89 | |
90 | ········bool isOid; |
91 | ········public bool IsOid |
92 | ········{ |
93 | ············get { return isOid; } |
94 | ········} |
95 | |
96 | ········public IList Fields |
97 | ········{ |
98 | ············get { return fields; } |
99 | ········} |
100 | |
101 | ········public string DataType |
102 | ········{ |
103 | ············get { return dataType; } |
104 | ········} |
105 | |
106 | ········public string Name |
107 | ········{ |
108 | ············get { return name; } |
109 | ········} |
110 | |
111 | ········public Type OidType |
112 | ········{ |
113 | ············get |
114 | ············{ |
115 | ················if (this.fieldType == typeof(int) |
116 | ····················|| this.fieldType == typeof(string) |
117 | ····················|| this.fieldType == typeof(Guid) |
118 | ····················|| this.fieldType == typeof(long)) |
119 | ····················return this.fieldType; |
120 | ················return null; |
121 | ············} |
122 | ········} |
123 | ········public override string ToString() |
124 | ········{ |
125 | ············return this.name; |
126 | ········} |
127 | ····} |
128 | } |
129 |
New Commit (dff5303)
1 | // |
2 | // Copyright (c) 2002-2016 Mirko Matytschak |
3 | // (www.netdataobjects.de) |
4 | // |
5 | // Author: Mirko Matytschak |
6 | // |
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
11 | // conditions: |
12 | |
13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
14 | // of the Software. |
15 | // |
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. |
21 | |
22 | |
23 | using System; |
24 | using System.Reflection; |
25 | using System.Collections; |
26 | using NDO; |
27 | using NDO.Mapping.Attributes; |
28 | |
29 | namespace NDOEnhancer |
30 | { |
31 | ····/// <summary> |
32 | ····/// Zusammenfassung für FieldNode. |
33 | ····/// </summary> |
34 | ····internal class FieldNode |
35 | ····{ |
36 | ········string dataType; |
37 | ········string name; |
38 | ········IList fields = new ArrayList(); |
39 | ········bool isEnum; |
40 | ········Type fieldType; |
41 | ········string declaringType; |
42 | ········bool isProperty; |
43 | ········public bool IsProperty |
44 | ········{ |
45 | ············get { return isProperty; } |
46 | ········} |
47 | |
48 | ········ColumnAttribute columnAttribute; |
49 | public ColumnAttribute ColumnAttribute => columnAttribute; |
50 | |
51 | FieldAttribute fieldAttribute; |
52 | public FieldAttribute FieldAttribute => this. fieldAttribute; |
53 | |
54 | ········public FieldNode(MemberInfo mi) |
55 | ········{········ |
56 | ············this.isProperty = (mi is PropertyInfo); |
57 | ············ |
58 | ············this.fieldType = isProperty ? ((PropertyInfo)mi).PropertyType : ((FieldInfo)mi).FieldType; |
59 | ············this.name = mi.Name; |
60 | #pragma warning disable 0618 |
61 | ············if (!isProperty) |
62 | ················this.isOid = mi.GetCustomAttributes(typeof(NDOObjectIdAttribute), false).Length > 0; |
63 | #pragma warning restore 0618 |
64 | ············this.dataType = new ReflectedType(this.fieldType).ILName; |
65 | ············if (!isProperty) |
66 | ············{ |
67 | ················if (mi.DeclaringType != mi.ReflectedType) |
68 | ····················this.declaringType = new ReflectedType(mi.DeclaringType).ILName; |
69 | ············} |
70 | ············this.isEnum = this.fieldType.IsEnum; |
71 | |
72 | ············object[] attrs = mi.GetCustomAttributes(typeof(ColumnAttribute), true); |
73 | ············if (attrs.Length > 0) // since ColumnAttribute.AllowMultiple == false, we can only have max 1 attr. |
74 | ················this.columnAttribute = (ColumnAttribute)attrs[0]; |
75 | |
76 | ············attrs = mi.GetCustomAttributes( typeof(FieldAttribute), true ); |
77 | ············if (attrs.Length > 0) |
78 | ················this.fieldAttribute = (FieldAttribute) attrs[0]; |
79 | ········} |
80 | |
81 | ········public Type FieldType |
82 | ········{ |
83 | ············get |
84 | ············{ |
85 | ················return fieldType; |
86 | ············} |
87 | ········} |
88 | |
89 | ········public bool IsEnum |
90 | ········{ |
91 | ············get { return isEnum; } |
92 | ········} |
93 | |
94 | ········bool isOid; |
95 | ········public bool IsOid |
96 | ········{ |
97 | ············get { return isOid; } |
98 | ········} |
99 | |
100 | ········public IList Fields |
101 | ········{ |
102 | ············get { return fields; } |
103 | ········} |
104 | |
105 | ········public string DataType |
106 | ········{ |
107 | ············get { return dataType; } |
108 | ········} |
109 | |
110 | ········public string Name |
111 | ········{ |
112 | ············get { return name; } |
113 | ········} |
114 | |
115 | ········public Type OidType |
116 | ········{ |
117 | ············get |
118 | ············{ |
119 | ················if (this.fieldType == typeof(int) |
120 | ····················|| this.fieldType == typeof(string) |
121 | ····················|| this.fieldType == typeof(Guid) |
122 | ····················|| this.fieldType == typeof(long)) |
123 | ····················return this.fieldType; |
124 | ················return null; |
125 | ············} |
126 | ········} |
127 | ········public override string ToString() |
128 | ········{ |
129 | ············return this.name; |
130 | ········} |
131 | ····} |
132 | } |
133 |