@@ -55,7 +55,7 @@ protected virtual void RegisterNoVisiblePropertyMapping(string notVisiblePropert
55
55
{
56
56
// even seems repetitive, before unify this registration with the registration using Expression take in account that reflection operations
57
57
// done unsing expressions are faster than those done with pure reflection.
58
- MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
58
+ MemberInfo member = GetRequiredPropertyOrFieldByName ( notVisiblePropertyOrFieldName ) ;
59
59
MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
60
60
RegistePropertyMapping ( mapping , memberOf ) ;
61
61
}
@@ -105,9 +105,10 @@ protected void RegisterComponentMapping<TComponent>(Action<IComponentMapper<TCom
105
105
/// <typeparam name="TComponent">The type of the template.</typeparam>
106
106
public void Component < TComponent > ( Expression < Func < TEntity , IDictionary > > property , TComponent dynamicComponentTemplate , Action < IDynamicComponentMapper < TComponent > > mapping )
107
107
{
108
- if ( dynamicComponentTemplate is IDictionary < string , System . Type > dicTemplate )
108
+ if ( dynamicComponentTemplate is IEnumerable < KeyValuePair < string , System . Type > > template )
109
109
{
110
- RegisterDynamicComponentMapping ( property , dicTemplate , mapping ) ;
110
+ var componentType = CreateDynamicComponentTypeFromTemplate ( template ) ;
111
+ RegisterDynamicComponentMapping ( property , componentType , mapping ) ;
111
112
}
112
113
else
113
114
{
@@ -126,9 +127,10 @@ public void Component<TComponent>(Expression<Func<TEntity, IDictionary>> propert
126
127
/// <typeparam name="TComponent">The type of the template.</typeparam>
127
128
public void Component < TComponent > ( Expression < Func < TEntity , IDictionary < string , object > > > property , TComponent dynamicComponentTemplate , Action < IDynamicComponentMapper < TComponent > > mapping ) where TComponent : class
128
129
{
129
- if ( dynamicComponentTemplate is IDictionary < string , System . Type > dicTemplate )
130
+ if ( dynamicComponentTemplate is IEnumerable < KeyValuePair < string , System . Type > > template )
130
131
{
131
- RegisterDynamicComponentMapping ( property , dicTemplate , mapping ) ;
132
+ var componentType = CreateDynamicComponentTypeFromTemplate ( template ) ;
133
+ RegisterDynamicComponentMapping ( property , componentType , mapping ) ;
132
134
}
133
135
else
134
136
{
@@ -142,44 +144,45 @@ protected virtual void RegisterDynamicComponentMapping<TComponent>(Expression<Fu
142
144
MemberInfo memberOf = TypeExtensions . DecodeMemberAccessExpressionOf ( property ) ;
143
145
RegisterDynamicComponentMapping ( mapping , member , memberOf ) ;
144
146
}
145
-
146
- protected virtual void RegisterDynamicComponentMapping < TComponent > ( Expression < Func < TEntity , IDictionary < string , object > > > property , Action < IDynamicComponentMapper < TComponent > > mapping ) where TComponent : class
147
+
148
+ protected virtual void RegisterDynamicComponentMapping < TComponent > ( Expression < Func < TEntity , IDictionary > > property , System . Type componentType , Action < IDynamicComponentMapper < TComponent > > mapping )
147
149
{
148
150
MemberInfo member = TypeExtensions . DecodeMemberAccessExpression ( property ) ;
149
151
MemberInfo memberOf = TypeExtensions . DecodeMemberAccessExpressionOf ( property ) ;
150
- RegisterDynamicComponentMapping ( mapping , member , memberOf ) ;
152
+ RegisterDynamicComponentMapping ( componentType , mapping , member , memberOf ) ;
151
153
}
152
154
153
- protected virtual void RegisterDynamicComponentMapping < TComponent > (
154
- Expression < Func < TEntity , IDictionary > > property ,
155
- IDictionary < string , System . Type > template ,
156
- Action < IDynamicComponentMapper < TComponent > > mapping )
155
+ protected virtual void RegisterDynamicComponentMapping < TComponent > ( Expression < Func < TEntity , IDictionary < string , object > > > property , Action < IDynamicComponentMapper < TComponent > > mapping ) where TComponent : class
157
156
{
158
157
MemberInfo member = TypeExtensions . DecodeMemberAccessExpression ( property ) ;
159
158
MemberInfo memberOf = TypeExtensions . DecodeMemberAccessExpressionOf ( property ) ;
160
- RegisterDynamicComponentMapping ( template , mapping , member , memberOf ) ;
159
+ RegisterDynamicComponentMapping ( mapping , member , memberOf ) ;
161
160
}
162
161
163
- protected virtual void RegisterDynamicComponentMapping < TComponent > (
164
- Expression < Func < TEntity , IDictionary < string , object > > > property ,
165
- IDictionary < string , System . Type > template ,
166
- Action < IDynamicComponentMapper < TComponent > > mapping )
162
+ protected virtual void RegisterDynamicComponentMapping < TComponent > ( Expression < Func < TEntity , IDictionary < string , object > > > property , System . Type componentType , Action < IDynamicComponentMapper < TComponent > > mapping )
167
163
{
168
164
MemberInfo member = TypeExtensions . DecodeMemberAccessExpression ( property ) ;
169
165
MemberInfo memberOf = TypeExtensions . DecodeMemberAccessExpressionOf ( property ) ;
170
- RegisterDynamicComponentMapping ( template , mapping , member , memberOf ) ;
166
+ RegisterDynamicComponentMapping ( componentType , mapping , member , memberOf ) ;
171
167
}
172
168
173
- protected void RegisterDynamicComponentMapping < TComponent > ( IDictionary < string , System . Type > template , Action < IDynamicComponentMapper < TComponent > > mapping , params MemberInfo [ ] members )
169
+ protected void RegisterDynamicComponentMapping < TComponent > ( System . Type componentType , Action < IDynamicComponentMapper < TComponent > > mapping , params MemberInfo [ ] members )
174
170
{
175
- var componentType = CreateDynamicComponentTypeFromTemplate ( template ) ;
176
171
foreach ( var member in members )
177
172
{
178
173
mapping ( new DynamicComponentCustomizer < TComponent > ( componentType , explicitDeclarationsHolder , CustomizersHolder , new PropertyPath ( PropertyPath , member ) ) ) ;
179
174
}
180
175
}
181
176
182
- private static System . Type CreateDynamicComponentTypeFromTemplate ( IDictionary < string , System . Type > template )
177
+ protected void RegisterDynamicComponentMapping < TComponent > ( Action < IDynamicComponentMapper < TComponent > > mapping , params MemberInfo [ ] members )
178
+ {
179
+ foreach ( var member in members )
180
+ {
181
+ mapping ( new DynamicComponentCustomizer < TComponent > ( explicitDeclarationsHolder , CustomizersHolder , new PropertyPath ( PropertyPath , member ) ) ) ;
182
+ }
183
+ }
184
+
185
+ private static System . Type CreateDynamicComponentTypeFromTemplate ( IEnumerable < KeyValuePair < string , System . Type > > template )
183
186
{
184
187
var assemblyName = new AssemblyName ( "MyDynamicAssembly" ) ;
185
188
var assemblyBuilder = AssemblyBuilder . DefineDynamicAssembly ( assemblyName , AssemblyBuilderAccess . Run ) ;
@@ -223,14 +226,6 @@ private static System.Type CreateDynamicComponentTypeFromTemplate(IDictionary<st
223
226
return typeBuilder . CreateTypeInfo ( ) ;
224
227
}
225
228
226
- protected void RegisterDynamicComponentMapping < TComponent > ( Action < IDynamicComponentMapper < TComponent > > mapping , params MemberInfo [ ] members )
227
- {
228
- foreach ( var member in members )
229
- {
230
- mapping ( new DynamicComponentCustomizer < TComponent > ( explicitDeclarationsHolder , CustomizersHolder , new PropertyPath ( PropertyPath , member ) ) ) ;
231
- }
232
- }
233
-
234
229
public void ManyToOne < TProperty > ( Expression < Func < TEntity , TProperty > > property , Action < IManyToOneMapper > mapping )
235
230
where TProperty : class
236
231
{
@@ -270,7 +265,7 @@ public void OneToOne<TProperty>(Expression<Func<TEntity, TProperty>> property, A
270
265
271
266
public void OneToOne < TProperty > ( string notVisiblePropertyOrFieldName , Action < IOneToOneMapper < TProperty > > mapping ) where TProperty : class
272
267
{
273
- var member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
268
+ var member = GetRequiredPropertyOrFieldByName ( notVisiblePropertyOrFieldName ) ;
274
269
var propertyOrFieldType = member . GetPropertyOrFieldType ( ) ;
275
270
if ( typeof ( TProperty ) != propertyOrFieldType )
276
271
{
@@ -467,7 +462,7 @@ protected virtual void RegisterIdBagMapping<TElement>(Action<IIdBagPropertiesMap
467
462
468
463
public void Set < TElement > ( string notVisiblePropertyOrFieldName , Action < ISetPropertiesMapper < TEntity , TElement > > collectionMapping , Action < ICollectionElementRelation < TElement > > mapping )
469
464
{
470
- MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
465
+ MemberInfo member = GetRequiredPropertyOrFieldByName ( notVisiblePropertyOrFieldName ) ;
471
466
AssertCollectionElementType < TElement > ( notVisiblePropertyOrFieldName , member ) ;
472
467
473
468
MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
@@ -497,7 +492,7 @@ public void Set<TElement>(string notVisiblePropertyOrFieldName, Action<ISetPrope
497
492
498
493
public void Bag < TElement > ( string notVisiblePropertyOrFieldName , Action < IBagPropertiesMapper < TEntity , TElement > > collectionMapping , Action < ICollectionElementRelation < TElement > > mapping )
499
494
{
500
- MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
495
+ MemberInfo member = GetRequiredPropertyOrFieldByName ( notVisiblePropertyOrFieldName ) ;
501
496
AssertCollectionElementType < TElement > ( notVisiblePropertyOrFieldName , member ) ;
502
497
503
498
MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
@@ -511,7 +506,7 @@ public void Bag<TElement>(string notVisiblePropertyOrFieldName, Action<IBagPrope
511
506
512
507
public void List < TElement > ( string notVisiblePropertyOrFieldName , Action < IListPropertiesMapper < TEntity , TElement > > collectionMapping , Action < ICollectionElementRelation < TElement > > mapping )
513
508
{
514
- MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
509
+ MemberInfo member = GetRequiredPropertyOrFieldByName ( notVisiblePropertyOrFieldName ) ;
515
510
AssertCollectionElementType < TElement > ( notVisiblePropertyOrFieldName , member ) ;
516
511
517
512
MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
@@ -525,7 +520,7 @@ public void List<TElement>(string notVisiblePropertyOrFieldName, Action<IListPro
525
520
526
521
public void Map < TKey , TElement > ( string notVisiblePropertyOrFieldName , Action < IMapPropertiesMapper < TEntity , TKey , TElement > > collectionMapping , Action < IMapKeyRelation < TKey > > keyMapping , Action < ICollectionElementRelation < TElement > > mapping )
527
522
{
528
- MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
523
+ MemberInfo member = GetRequiredPropertyOrFieldByName ( notVisiblePropertyOrFieldName ) ;
529
524
var propertyOrFieldType = member . GetPropertyOrFieldType ( ) ;
530
525
var keyType = propertyOrFieldType . DetermineDictionaryKeyType ( ) ;
531
526
var collectionElementType = propertyOrFieldType . DetermineDictionaryValueType ( ) ;
@@ -550,7 +545,7 @@ public void Map<TKey, TElement>(string notVisiblePropertyOrFieldName, Action<IMa
550
545
551
546
public void IdBag < TElement > ( string notVisiblePropertyOrFieldName , Action < IIdBagPropertiesMapper < TEntity , TElement > > collectionMapping , Action < ICollectionElementRelation < TElement > > mapping )
552
547
{
553
- MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
548
+ MemberInfo member = GetRequiredPropertyOrFieldByName ( notVisiblePropertyOrFieldName ) ;
554
549
AssertCollectionElementType < TElement > ( notVisiblePropertyOrFieldName , member ) ;
555
550
556
551
MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
@@ -564,7 +559,7 @@ public void IdBag<TElement>(string notVisiblePropertyOrFieldName, Action<IIdBagP
564
559
565
560
public void ManyToOne < TProperty > ( string notVisiblePropertyOrFieldName , Action < IManyToOneMapper > mapping ) where TProperty : class
566
561
{
567
- MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
562
+ MemberInfo member = GetRequiredPropertyOrFieldByName ( notVisiblePropertyOrFieldName ) ;
568
563
var propertyOrFieldType = member . GetPropertyOrFieldType ( ) ;
569
564
if ( ! typeof ( TProperty ) . Equals ( propertyOrFieldType ) )
570
565
{
@@ -577,7 +572,7 @@ public void ManyToOne<TProperty>(string notVisiblePropertyOrFieldName, Action<IM
577
572
578
573
public void Component < TComponent > ( string notVisiblePropertyOrFieldName , Action < IComponentMapper < TComponent > > mapping )
579
574
{
580
- MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
575
+ MemberInfo member = GetRequiredPropertyOrFieldByName ( notVisiblePropertyOrFieldName ) ;
581
576
var propertyOrFieldType = member . GetPropertyOrFieldType ( ) ;
582
577
if ( ! typeof ( TComponent ) . Equals ( propertyOrFieldType ) )
583
578
{
@@ -605,12 +600,13 @@ public void Component<TComponent>(string notVisiblePropertyOrFieldName)
605
600
/// <typeparam name="TComponent">The type of the template.</typeparam>
606
601
public void Component < TComponent > ( string notVisiblePropertyOrFieldName , TComponent dynamicComponentTemplate , Action < IDynamicComponentMapper < TComponent > > mapping )
607
602
{
608
- MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
603
+ MemberInfo member = GetRequiredPropertyOrFieldByName ( notVisiblePropertyOrFieldName ) ;
609
604
MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
610
605
611
- if ( dynamicComponentTemplate is IDictionary < string , System . Type > dicTemplate )
606
+ if ( dynamicComponentTemplate is IEnumerable < KeyValuePair < string , System . Type > > template )
612
607
{
613
- RegisterDynamicComponentMapping ( dicTemplate , mapping , member , memberOf ) ;
608
+ var componentType = CreateDynamicComponentTypeFromTemplate ( template ) ;
609
+ RegisterDynamicComponentMapping ( componentType , mapping , member , memberOf ) ;
614
610
}
615
611
else
616
612
{
@@ -620,7 +616,7 @@ public void Component<TComponent>(string notVisiblePropertyOrFieldName, TCompone
620
616
621
617
public void Any < TProperty > ( string notVisiblePropertyOrFieldName , System . Type idTypeOfMetaType , Action < IAnyMapper > mapping ) where TProperty : class
622
618
{
623
- MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
619
+ MemberInfo member = GetRequiredPropertyOrFieldByName ( notVisiblePropertyOrFieldName ) ;
624
620
var propertyOrFieldType = member . GetPropertyOrFieldType ( ) ;
625
621
if ( ! typeof ( TProperty ) . Equals ( propertyOrFieldType ) )
626
622
{
@@ -631,6 +627,14 @@ public void Any<TProperty>(string notVisiblePropertyOrFieldName, System.Type idT
631
627
RegisterAnyMapping < TProperty > ( mapping , idTypeOfMetaType , member , memberOf ) ;
632
628
}
633
629
630
+ protected virtual MemberInfo GetRequiredPropertyOrFieldByName ( string memberName )
631
+ {
632
+ #pragma warning disable 618
633
+ return GetPropertyOrFieldMatchingNameOrThrow ( memberName ) ;
634
+ #pragma warning restore 618
635
+ }
636
+
637
+ [ Obsolete ( "Please use GetRequiredPropertyOrFieldByName instead." ) ]
634
638
public static MemberInfo GetPropertyOrFieldMatchingNameOrThrow ( string memberName )
635
639
{
636
640
var result = typeof ( TEntity ) . GetPropertyOrFieldMatchingName ( memberName ) ;
0 commit comments