44using NHibernate . Mapping ;
55using System ;
66using NHibernate . Util ;
7- using Array = System . Array ;
87
98namespace NHibernate . Cfg . XmlHbmBinding
109{
@@ -14,7 +13,6 @@ public class PropertiesBinder : ClassBinder
1413 private readonly Component component ;
1514 private readonly string entityName ;
1615 private readonly System . Type mappedClass ;
17- private readonly string className ;
1816 private readonly bool componetDefaultNullable ;
1917 private readonly string propertyBasePath ;
2018
@@ -38,7 +36,6 @@ public PropertiesBinder(Mappings mappings, PersistentClass persistentClass)
3836 this . persistentClass = persistentClass ;
3937 entityName = persistentClass . EntityName ;
4038 propertyBasePath = entityName ;
41- className = persistentClass . ClassName ;
4239 mappedClass = persistentClass . MappedClass ;
4340 componetDefaultNullable = true ;
4441 component = null ;
@@ -50,7 +47,6 @@ public PropertiesBinder(Mappings mappings, Component component, string className
5047 persistentClass = component . Owner ;
5148 this . component = component ;
5249 entityName = className ;
53- this . className = component . ComponentClassName ;
5450 mappedClass = component . ComponentClass ;
5551 propertyBasePath = path ;
5652 componetDefaultNullable = isNullable ;
@@ -87,26 +83,14 @@ public void Bind(IEnumerable<IEntityPropertyMapping> properties, Table table, ID
8783
8884 string propertyName = entityPropertyMapping . Name ;
8985
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 )
10387 {
10488 var value = new SimpleValue ( table ) ;
10589 new ValuePropertyBinder ( value , Mappings ) . BindSimpleValue ( propertyMapping , propertyName , true ) ;
106- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
90+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
10791 BindValueProperty ( propertyMapping , property ) ;
10892 }
109- else if ( ( collectionMapping = entityPropertyMapping as ICollectionPropertiesMapping ) != null )
93+ else if ( entityPropertyMapping is ICollectionPropertiesMapping collectionMapping )
11094 {
11195 var collectionBinder = new CollectionBinder ( Mappings ) ;
11296 string propertyPath = propertyName == null ? null : StringHelper . Qualify ( propertyBasePath , propertyName ) ;
@@ -116,59 +100,59 @@ public void Bind(IEnumerable<IEntityPropertyMapping> properties, Table table, ID
116100
117101 mappings . AddCollection ( collection ) ;
118102
119- property = CreateProperty ( collectionMapping , className , collection , inheritedMetas ) ;
103+ property = CreateProperty ( collectionMapping , mappedClass , collection , inheritedMetas ) ;
120104 BindCollectionProperty ( collectionMapping , property ) ;
121105 }
122- else if ( ( propertiesMapping = entityPropertyMapping as HbmProperties ) != null )
106+ else if ( entityPropertyMapping is HbmProperties propertiesMapping )
123107 {
124108 var subpath = propertyName == null ? null : StringHelper . Qualify ( propertyBasePath , propertyName ) ;
125109 var value = CreateNewComponent ( table ) ;
126110 BindComponent ( propertiesMapping , value , null , entityName , subpath , componetDefaultNullable , inheritedMetas ) ;
127- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
111+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
128112 BindComponentProperty ( propertiesMapping , property , value ) ;
129113 }
130- else if ( ( manyToOneMapping = entityPropertyMapping as HbmManyToOne ) != null )
114+ else if ( entityPropertyMapping is HbmManyToOne manyToOneMapping )
131115 {
132116 var value = new ManyToOne ( table ) ;
133117 BindManyToOne ( manyToOneMapping , value , propertyName , true ) ;
134- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
118+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
135119 BindManyToOneProperty ( manyToOneMapping , property ) ;
136120 }
137- else if ( ( componentMapping = entityPropertyMapping as HbmComponent ) != null )
121+ else if ( entityPropertyMapping is HbmComponent componentMapping )
138122 {
139123 string subpath = propertyName == null ? null : StringHelper . Qualify ( propertyBasePath , propertyName ) ;
140124 var value = CreateNewComponent ( table ) ;
141125 // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
142126 System . Type reflectedClass = mappedClass == null ? null : GetPropertyType ( componentMapping . Class , mappedClass , propertyName , componentMapping . Access ) ;
143127 BindComponent ( componentMapping , value , reflectedClass , entityName , subpath , componetDefaultNullable , inheritedMetas ) ;
144- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
128+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
145129 BindComponentProperty ( componentMapping , property , value ) ;
146130 }
147- else if ( ( oneToOneMapping = entityPropertyMapping as HbmOneToOne ) != null )
131+ else if ( entityPropertyMapping is HbmOneToOne oneToOneMapping )
148132 {
149133 var value = new OneToOne ( table , persistentClass ) ;
150134 BindOneToOne ( oneToOneMapping , value ) ;
151- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
135+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
152136 BindOneToOneProperty ( oneToOneMapping , property ) ;
153137 }
154- else if ( ( dynamicComponentMapping = entityPropertyMapping as HbmDynamicComponent ) != null )
138+ else if ( entityPropertyMapping is HbmDynamicComponent dynamicComponentMapping )
155139 {
156140 string subpath = propertyName == null ? null : StringHelper . Qualify ( propertyBasePath , propertyName ) ;
157141 var value = CreateNewComponent ( table ) ;
158142 // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
159143 System . Type reflectedClass = mappedClass == null ? null : GetPropertyType ( dynamicComponentMapping . Class , mappedClass , propertyName , dynamicComponentMapping . Access ) ;
160144 BindComponent ( dynamicComponentMapping , value , reflectedClass , entityName , subpath , componetDefaultNullable , inheritedMetas ) ;
161- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
145+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
162146 BindComponentProperty ( dynamicComponentMapping , property , value ) ;
163147 }
164- else if ( ( anyMapping = entityPropertyMapping as HbmAny ) != null )
148+ else if ( entityPropertyMapping is HbmAny anyMapping )
165149 {
166150 var value = new Any ( table ) ;
167151 BindAny ( anyMapping , value , true ) ;
168- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
152+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
169153 BindAnyProperty ( anyMapping , property ) ;
170154 }
171- else if ( ( nestedCompositeElementMapping = entityPropertyMapping as HbmNestedCompositeElement ) != null )
155+ else if ( entityPropertyMapping is HbmNestedCompositeElement nestedCompositeElementMapping )
172156 {
173157 if ( component == null )
174158 {
@@ -179,19 +163,19 @@ public void Bind(IEnumerable<IEntityPropertyMapping> properties, Table table, ID
179163 // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
180164 System . Type reflectedClass = mappedClass == null ? null : GetPropertyType ( nestedCompositeElementMapping . Class , mappedClass , propertyName , nestedCompositeElementMapping . access ) ;
181165 BindComponent ( nestedCompositeElementMapping , value , reflectedClass , entityName , subpath , componetDefaultNullable , inheritedMetas ) ;
182- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
166+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
183167 }
184- else if ( ( keyPropertyMapping = entityPropertyMapping as HbmKeyProperty ) != null )
168+ else if ( entityPropertyMapping is HbmKeyProperty keyPropertyMapping )
185169 {
186170 var value = new SimpleValue ( table ) ;
187171 new ValuePropertyBinder ( value , Mappings ) . BindSimpleValue ( keyPropertyMapping , propertyName , componetDefaultNullable ) ;
188- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
172+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
189173 }
190- else if ( ( keyManyToOneMapping = entityPropertyMapping as HbmKeyManyToOne ) != null )
174+ else if ( entityPropertyMapping is HbmKeyManyToOne keyManyToOneMapping )
191175 {
192176 var value = new ManyToOne ( table ) ;
193177 BindKeyManyToOne ( keyManyToOneMapping , value , propertyName , componetDefaultNullable ) ;
194- property = CreateProperty ( entityPropertyMapping , className , value , inheritedMetas ) ;
178+ property = CreateProperty ( entityPropertyMapping , mappedClass , value , inheritedMetas ) ;
195179 }
196180
197181 if ( property != null )
@@ -402,30 +386,27 @@ private void BindCollectionProperty(ICollectionPropertiesMapping collectionMappi
402386 property . Cascade = collectionMapping . Cascade ?? mappings . DefaultCascade ;
403387 }
404388
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 )
406390 {
391+ var type = propertyOwnerType ? . UnwrapIfNullable ( ) ;
407392 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 + "]" ) ;
411394
412395 var propertyAccessorName = GetPropertyAccessorName ( propertyMapping . Access ) ;
413396
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 ) ;
416399
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+ } ;
429410 }
430411
431412 private string GetPropertyAccessorName ( string propertyMappedAccessor )
0 commit comments