Datei: NDOEnhancer/NDOEnhancer/Enhancer/Nodes/FieldNode.cs

Last Commit (6940b24)
1 //
2 // Copyright (c) 2002-2022 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 NDO;
26 using NDO.Mapping.Attributes;
27 using System.Collections.Generic;
 
28
29 namespace NDOEnhancer
30 {
31 ····/// <summary>
32 ····/// Zusammenfassung für FieldNode.
33 ····/// </summary>
34 ····public class FieldNode
35 ····{
36 ········string dataType;
37 ········string name;
38 ········List<FieldNode> fields = new List<FieldNode>();
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
61 #warning this. isOid should be set by the information provided by the class' attribute OidColumn( fieldName)
 
 
 
 
62
63 ············this.dataType = new ReflectedType(this.fieldType).ILName;
64 ············if (!isProperty)
65 ············{
66 ················if (mi.DeclaringType != mi.ReflectedType)
67 ····················this.declaringType = new ReflectedType(mi.DeclaringType).ILName;
68 ············}
69 ············this.isEnum = this.fieldType.IsEnum;
70
71 ············object[] attrs = mi.GetCustomAttributes(typeof(ColumnAttribute), true);
72 ············if (attrs.Length > 0) // since ColumnAttribute.AllowMultiple == false, we can only have max 1 attr.
73 ················this.columnAttribute = (ColumnAttribute)attrs[0];
74
75 ············attrs = mi.GetCustomAttributes( typeof(FieldAttribute), true );
76 ············if (attrs.Length > 0)
77 ················this.fieldAttribute = (FieldAttribute) attrs[0];
78 ········}
79
80 ········public Type FieldType
81 ········{
82 ············get
83 ············{
84 ················return fieldType;
85 ············}
86 ········}
87
88 ········public bool IsEnum
89 ········{
90 ············get { return isEnum; }
91 ········}
92
93 ········bool isOid;
94 ········public bool IsOid
95 ········{
96 ············get { return isOid; }
97 ········}
98
99 ········public IEnumerable<FieldNode> Fields
100 ········{
101 ············get { return fields; }
102 ········}
103
104 ········public string DataType
105 ········{
106 ············get { return dataType; }
107 ········}
108
109 ········public string Name
110 ········{
111 ············get { return name; }
112 ········}
113
114 ········/// <summary>
115 ········/// Add a subfield in case of embedded fields
116 ········/// </summary>
117 ········/// <param name="fieldNode"></param>
118 ········public void AddField(FieldNode fieldNode)
119 ········{
120 ············this.fields.Add( fieldNode );
121 ········}
122
123 ········public Type OidType
124 ········{
125 ············get
126 ············{
127 ················if (this.fieldType == typeof(int)
128 ····················|| this.fieldType == typeof(string)
129 ····················|| this.fieldType == typeof(Guid)
130 ····················|| this.fieldType == typeof(long))
131 ····················return this.fieldType;
132 ················return null;
133 ············}
134 ········}
135 ········public override string ToString()
136 ········{
137 ············return this.name;
138 ········}
139 ····}
140 }
141
New Commit (189787b)
1 //
2 // Copyright (c) 2002-2022 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 NDO;
26 using NDO.Mapping.Attributes;
27 using System.Collections.Generic;
28 using System.Linq;
29
30 namespace NDOEnhancer
31 {
32 ····/// <summary>
33 ····/// Zusammenfassung für FieldNode.
34 ····/// </summary>
35 ····public class FieldNode
36 ····{
37 ········string dataType;
38 ········string name;
39 ········List<FieldNode> fields = new List<FieldNode>();
40 ········bool isEnum;
41 ········Type fieldType;
42 ········string declaringType;
43 ········bool isProperty;
44 ········public bool IsProperty
45 ········{
46 ············get { return isProperty; }
47 ········}
48
49 ········ColumnAttribute columnAttribute;
50 ········public ColumnAttribute ColumnAttribute => columnAttribute;
51
52 ········FieldAttribute fieldAttribute;
53 ········public FieldAttribute FieldAttribute => this.fieldAttribute;
54
55 ········public FieldNode(MemberInfo mi)
56 ········{········
57 ············this.isProperty = (mi is PropertyInfo);
58 ············
59 ············this.fieldType = isProperty ? ((PropertyInfo)mi).PropertyType : ((FieldInfo)mi).FieldType;
60 ············this.name = mi.Name;
61
62 // If the class has an OidColumn attribute which sets the fieldName to the name of the
63 ············// given field, the field is an oid field.
64 ············var oidc = (OidColumnAttribute) mi.DeclaringType.GetCustomAttributes().FirstOrDefault(a => a is OidColumnAttribute);
65 ············if (oidc != null && oidc.FieldName == mi.Name)
66 ················this.isOid = true;
67
68 ············this.dataType = new ReflectedType(this.fieldType).ILName;
69 ············if (!isProperty)
70 ············{
71 ················if (mi.DeclaringType != mi.ReflectedType)
72 ····················this.declaringType = new ReflectedType(mi.DeclaringType).ILName;
73 ············}
74 ············this.isEnum = this.fieldType.IsEnum;
75
76 ············object[] attrs = mi.GetCustomAttributes(typeof(ColumnAttribute), true);
77 ············if (attrs.Length > 0) // since ColumnAttribute.AllowMultiple == false, we can only have max 1 attr.
78 ················this.columnAttribute = (ColumnAttribute)attrs[0];
79
80 ············attrs = mi.GetCustomAttributes( typeof(FieldAttribute), true );
81 ············if (attrs.Length > 0)
82 ················this.fieldAttribute = (FieldAttribute) attrs[0];
83 ········}
84
85 ········public Type FieldType
86 ········{
87 ············get
88 ············{
89 ················return fieldType;
90 ············}
91 ········}
92
93 ········public bool IsEnum
94 ········{
95 ············get { return isEnum; }
96 ········}
97
98 ········bool isOid;
99 ········public bool IsOid
100 ········{
101 ············get { return isOid; }
102 ········}
103
104 ········public IEnumerable<FieldNode> Fields
105 ········{
106 ············get { return fields; }
107 ········}
108
109 ········public string DataType
110 ········{
111 ············get { return dataType; }
112 ········}
113
114 ········public string Name
115 ········{
116 ············get { return name; }
117 ········}
118
119 ········/// <summary>
120 ········/// Add a subfield in case of embedded fields
121 ········/// </summary>
122 ········/// <param name="fieldNode"></param>
123 ········public void AddField(FieldNode fieldNode)
124 ········{
125 ············this.fields.Add( fieldNode );
126 ········}
127
128 ········public Type OidType
129 ········{
130 ············get
131 ············{
132 ················if (this.fieldType == typeof(int)
133 ····················|| this.fieldType == typeof(string)
134 ····················|| this.fieldType == typeof(Guid)
135 ····················|| this.fieldType == typeof(long))
136 ····················return this.fieldType;
137 ················return null;
138 ············}
139 ········}
140 ········public override string ToString()
141 ········{
142 ············return this.name;
143 ········}
144 ····}
145 }
146