4
4
using NHibernate . Mapping ;
5
5
using System ;
6
6
using NHibernate . Util ;
7
- using Array = System . Array ;
8
7
9
8
namespace NHibernate . Cfg . XmlHbmBinding
10
9
{
@@ -14,7 +13,6 @@ public class PropertiesBinder : ClassBinder
14
13
private readonly Component component ;
15
14
private readonly string entityName ;
16
15
private readonly System . Type mappedClass ;
17
- private readonly string className ;
18
16
private readonly bool componetDefaultNullable ;
19
17
private readonly string propertyBasePath ;
20
18
@@ -38,7 +36,6 @@ public PropertiesBinder(Mappings mappings, PersistentClass persistentClass)
38
36
this . persistentClass = persistentClass ;
39
37
entityName = persistentClass . EntityName ;
40
38
propertyBasePath = entityName ;
41
- className = persistentClass . ClassName ;
42
39
mappedClass = persistentClass . MappedClass ;
43
40
componetDefaultNullable = true ;
44
41
component = null ;
@@ -50,7 +47,6 @@ public PropertiesBinder(Mappings mappings, Component component, string className
50
47
persistentClass = component . Owner ;
51
48
this . component = component ;
52
49
entityName = className ;
53
- this . className = component . ComponentClassName ;
54
50
mappedClass = component . ComponentClass ;
55
51
propertyBasePath = path ;
56
52
componetDefaultNullable = isNullable ;
@@ -87,26 +83,14 @@ public void Bind(IEnumerable<IEntityPropertyMapping> properties, Table table, ID
87
83
88
84
string propertyName = entityPropertyMapping . Name ;
89
85
90
- ICollectionPropertiesMapping collectionMapping ;
91
- HbmManyToOne manyToOneMapping ;
92
- HbmAny anyMapping ;
93
- HbmOneToOne oneToOneMapping ;
94
- HbmProperty propertyMapping ;
95
- HbmComponent componentMapping ;
96
- HbmDynamicComponent dynamicComponentMapping ;
97
- HbmNestedCompositeElement nestedCompositeElementMapping ;
98
- HbmKeyProperty keyPropertyMapping ;
99
- HbmKeyManyToOne keyManyToOneMapping ;
100
- HbmProperties propertiesMapping ;
101
-
102
- if ( ( propertyMapping = entityPropertyMapping as HbmProperty ) != null )
86
+ if ( entityPropertyMapping is HbmProperty propertyMapping )
103
87
{
104
88
var value = new SimpleValue ( table ) ;
105
89
new ValuePropertyBinder ( value , Mappings ) . BindSimpleValue ( propertyMapping , propertyName , true ) ;
106
- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
90
+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
107
91
BindValueProperty ( propertyMapping , property ) ;
108
92
}
109
- else if ( ( collectionMapping = entityPropertyMapping as ICollectionPropertiesMapping ) != null )
93
+ else if ( entityPropertyMapping is ICollectionPropertiesMapping collectionMapping )
110
94
{
111
95
var collectionBinder = new CollectionBinder ( Mappings ) ;
112
96
string propertyPath = propertyName == null ? null : StringHelper . Qualify ( propertyBasePath , propertyName ) ;
@@ -116,59 +100,59 @@ public void Bind(IEnumerable<IEntityPropertyMapping> properties, Table table, ID
116
100
117
101
mappings . AddCollection ( collection ) ;
118
102
119
- property = CreateProperty ( collectionMapping , className , collection , inheritedMetas ) ;
103
+ property = CreateProperty ( collectionMapping , mappedClass , collection , inheritedMetas ) ;
120
104
BindCollectionProperty ( collectionMapping , property ) ;
121
105
}
122
- else if ( ( propertiesMapping = entityPropertyMapping as HbmProperties ) != null )
106
+ else if ( entityPropertyMapping is HbmProperties propertiesMapping )
123
107
{
124
108
var subpath = propertyName == null ? null : StringHelper . Qualify ( propertyBasePath , propertyName ) ;
125
109
var value = CreateNewComponent ( table ) ;
126
110
BindComponent ( propertiesMapping , value , null , entityName , subpath , componetDefaultNullable , inheritedMetas ) ;
127
- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
111
+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
128
112
BindComponentProperty ( propertiesMapping , property , value ) ;
129
113
}
130
- else if ( ( manyToOneMapping = entityPropertyMapping as HbmManyToOne ) != null )
114
+ else if ( entityPropertyMapping is HbmManyToOne manyToOneMapping )
131
115
{
132
116
var value = new ManyToOne ( table ) ;
133
117
BindManyToOne ( manyToOneMapping , value , propertyName , true ) ;
134
- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
118
+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
135
119
BindManyToOneProperty ( manyToOneMapping , property ) ;
136
120
}
137
- else if ( ( componentMapping = entityPropertyMapping as HbmComponent ) != null )
121
+ else if ( entityPropertyMapping is HbmComponent componentMapping )
138
122
{
139
123
string subpath = propertyName == null ? null : StringHelper . Qualify ( propertyBasePath , propertyName ) ;
140
124
var value = CreateNewComponent ( table ) ;
141
125
// NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
142
126
System . Type reflectedClass = mappedClass == null ? null : GetPropertyType ( componentMapping . Class , mappedClass , propertyName , componentMapping . Access ) ;
143
127
BindComponent ( componentMapping , value , reflectedClass , entityName , subpath , componetDefaultNullable , inheritedMetas ) ;
144
- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
128
+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
145
129
BindComponentProperty ( componentMapping , property , value ) ;
146
130
}
147
- else if ( ( oneToOneMapping = entityPropertyMapping as HbmOneToOne ) != null )
131
+ else if ( entityPropertyMapping is HbmOneToOne oneToOneMapping )
148
132
{
149
133
var value = new OneToOne ( table , persistentClass ) ;
150
134
BindOneToOne ( oneToOneMapping , value ) ;
151
- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
135
+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
152
136
BindOneToOneProperty ( oneToOneMapping , property ) ;
153
137
}
154
- else if ( ( dynamicComponentMapping = entityPropertyMapping as HbmDynamicComponent ) != null )
138
+ else if ( entityPropertyMapping is HbmDynamicComponent dynamicComponentMapping )
155
139
{
156
140
string subpath = propertyName == null ? null : StringHelper . Qualify ( propertyBasePath , propertyName ) ;
157
141
var value = CreateNewComponent ( table ) ;
158
142
// NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
159
143
System . Type reflectedClass = mappedClass == null ? null : GetPropertyType ( dynamicComponentMapping . Class , mappedClass , propertyName , dynamicComponentMapping . Access ) ;
160
144
BindComponent ( dynamicComponentMapping , value , reflectedClass , entityName , subpath , componetDefaultNullable , inheritedMetas ) ;
161
- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
145
+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
162
146
BindComponentProperty ( dynamicComponentMapping , property , value ) ;
163
147
}
164
- else if ( ( anyMapping = entityPropertyMapping as HbmAny ) != null )
148
+ else if ( entityPropertyMapping is HbmAny anyMapping )
165
149
{
166
150
var value = new Any ( table ) ;
167
151
BindAny ( anyMapping , value , true ) ;
168
- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
152
+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
169
153
BindAnyProperty ( anyMapping , property ) ;
170
154
}
171
- else if ( ( nestedCompositeElementMapping = entityPropertyMapping as HbmNestedCompositeElement ) != null )
155
+ else if ( entityPropertyMapping is HbmNestedCompositeElement nestedCompositeElementMapping )
172
156
{
173
157
if ( component == null )
174
158
{
@@ -179,19 +163,19 @@ public void Bind(IEnumerable<IEntityPropertyMapping> properties, Table table, ID
179
163
// NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
180
164
System . Type reflectedClass = mappedClass == null ? null : GetPropertyType ( nestedCompositeElementMapping . Class , mappedClass , propertyName , nestedCompositeElementMapping . access ) ;
181
165
BindComponent ( nestedCompositeElementMapping , value , reflectedClass , entityName , subpath , componetDefaultNullable , inheritedMetas ) ;
182
- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
166
+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
183
167
}
184
- else if ( ( keyPropertyMapping = entityPropertyMapping as HbmKeyProperty ) != null )
168
+ else if ( entityPropertyMapping is HbmKeyProperty keyPropertyMapping )
185
169
{
186
170
var value = new SimpleValue ( table ) ;
187
171
new ValuePropertyBinder ( value , Mappings ) . BindSimpleValue ( keyPropertyMapping , propertyName , componetDefaultNullable ) ;
188
- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
172
+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
189
173
}
190
- else if ( ( keyManyToOneMapping = entityPropertyMapping as HbmKeyManyToOne ) != null )
174
+ else if ( entityPropertyMapping is HbmKeyManyToOne keyManyToOneMapping )
191
175
{
192
176
var value = new ManyToOne ( table ) ;
193
177
BindKeyManyToOne ( keyManyToOneMapping , value , propertyName , componetDefaultNullable ) ;
194
- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
178
+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
195
179
}
196
180
197
181
if ( property != null )
@@ -402,30 +386,27 @@ private void BindCollectionProperty(ICollectionPropertiesMapping collectionMappi
402
386
property . Cascade = collectionMapping . Cascade ?? mappings . DefaultCascade ;
403
387
}
404
388
405
- private Property CreateProperty ( IEntityPropertyMapping propertyMapping , string propertyOwnerClassName , IValue value , IDictionary < string , MetaAttribute > inheritedMetas )
389
+ private Property CreateProperty ( IEntityPropertyMapping propertyMapping , System . Type propertyOwnerType , IValue value , IDictionary < string , MetaAttribute > inheritedMetas )
406
390
{
391
+ var type = propertyOwnerType ? . UnwrapIfNullable ( ) ;
407
392
if ( string . IsNullOrEmpty ( propertyMapping . Name ) )
408
- {
409
- throw new MappingException ( "A property mapping must define the name attribute [" + propertyOwnerClassName + "]" ) ;
410
- }
393
+ throw new MappingException ( "A property mapping must define the name attribute [" + type + "]" ) ;
411
394
412
395
var propertyAccessorName = GetPropertyAccessorName ( propertyMapping . Access ) ;
413
396
414
- if ( ! string . IsNullOrEmpty ( propertyOwnerClassName ) && value . IsSimpleValue )
415
- value . SetTypeUsingReflection ( propertyOwnerClassName , propertyMapping . Name , propertyAccessorName ) ;
397
+ if ( type != null && value . IsSimpleValue )
398
+ value . SetTypeUsingReflection ( type . AssemblyQualifiedName , propertyMapping . Name , propertyAccessorName ) ;
416
399
417
- var property = new Property
418
- {
419
- Name = propertyMapping . Name ,
420
- PropertyAccessorName = propertyAccessorName ,
421
- Value = value ,
422
- IsLazy = propertyMapping . IsLazyProperty ,
423
- LazyGroup = propertyMapping . GetLazyGroup ( ) ,
424
- IsOptimisticLocked = propertyMapping . OptimisticLock ,
425
- MetaAttributes = GetMetas ( propertyMapping , inheritedMetas )
426
- } ;
427
-
428
- return property ;
400
+ return new Property
401
+ {
402
+ Name = propertyMapping . Name ,
403
+ PropertyAccessorName = propertyAccessorName ,
404
+ Value = value ,
405
+ IsLazy = propertyMapping . IsLazyProperty ,
406
+ LazyGroup = propertyMapping . GetLazyGroup ( ) ,
407
+ IsOptimisticLocked = propertyMapping . OptimisticLock ,
408
+ MetaAttributes = GetMetas ( propertyMapping , inheritedMetas )
409
+ } ;
429
410
}
430
411
431
412
private string GetPropertyAccessorName ( string propertyMappedAccessor )
0 commit comments