@@ -70,7 +70,7 @@ protected void RegistePropertyMapping(Action<IPropertyMapper> mapping, params Me
70
70
}
71
71
72
72
public void Component < TComponent > ( Expression < Func < TEntity , TComponent > > property ,
73
- Action < IComponentMapper < TComponent > > mapping ) where TComponent : class
73
+ Action < IComponentMapper < TComponent > > mapping ) where TComponent : class
74
74
{
75
75
RegisterComponentMapping ( property , mapping ) ;
76
76
}
@@ -148,20 +148,33 @@ public void ManyToOne<TProperty>(Expression<Func<TEntity, TProperty>> property)
148
148
ManyToOne ( property , x => { } ) ;
149
149
}
150
150
151
- public void OneToOne < TProperty > ( Expression < Func < TEntity , TProperty > > property , Action < IOneToOneMapper > mapping )
151
+ public void OneToOne < TProperty > ( Expression < Func < TEntity , TProperty > > property , Action < IOneToOneMapper < TProperty > > mapping )
152
152
where TProperty : class
153
153
{
154
- MemberInfo member = TypeExtensions . DecodeMemberAccessExpression ( property ) ;
155
- MemberInfo memberOf = TypeExtensions . DecodeMemberAccessExpressionOf ( property ) ;
156
- RegisterOneToOneMapping < TProperty > ( mapping , member , memberOf ) ;
154
+ var member = TypeExtensions . DecodeMemberAccessExpression ( property ) ;
155
+ var memberOf = TypeExtensions . DecodeMemberAccessExpressionOf ( property ) ;
156
+ RegisterOneToOneMapping ( mapping , member , memberOf ) ;
157
157
}
158
158
159
- protected void RegisterOneToOneMapping < TProperty > ( Action < IOneToOneMapper > mapping , params MemberInfo [ ] members )
159
+ public void OneToOne < TProperty > ( string notVisiblePropertyOrFieldName , Action < IOneToOneMapper < TProperty > > mapping ) where TProperty : class
160
+ {
161
+ var member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
162
+ var propertyOrFieldType = member . GetPropertyOrFieldType ( ) ;
163
+ if ( typeof ( TProperty ) != propertyOrFieldType )
164
+ {
165
+ throw new MappingException ( string . Format ( "Wrong relation type. For the property/field '{0}' of {1} was expected a one-to-one with {2} but was {3}" ,
166
+ notVisiblePropertyOrFieldName , typeof ( TEntity ) . FullName , typeof ( TProperty ) . Name , propertyOrFieldType . Name ) ) ;
167
+ }
168
+ var memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
169
+ RegisterOneToOneMapping ( mapping , member , memberOf ) ;
170
+ }
171
+
172
+ protected void RegisterOneToOneMapping < TProperty > ( Action < IOneToOneMapper < TProperty > > mapping , params MemberInfo [ ] members )
160
173
where TProperty : class
161
174
{
162
175
foreach ( var member in members )
163
176
{
164
- CustomizersHolder . AddCustomizer ( new PropertyPath ( PropertyPath , member ) , mapping ) ;
177
+ CustomizersHolder . AddCustomizer ( new PropertyPath ( PropertyPath , member ) , ( IOneToOneMapper x ) => mapping ( ( IOneToOneMapper < TProperty > ) x ) ) ;
165
178
explicitDeclarationsHolder . AddAsOneToOneRelation ( member ) ;
166
179
}
167
180
}
@@ -193,8 +206,8 @@ protected void RegisterAnyMapping<TProperty>(Action<IAnyMapper> mapping, System.
193
206
}
194
207
195
208
public void Set < TElement > ( Expression < Func < TEntity , IEnumerable < TElement > > > property ,
196
- Action < ISetPropertiesMapper < TEntity , TElement > > collectionMapping ,
197
- Action < ICollectionElementRelation < TElement > > mapping )
209
+ Action < ISetPropertiesMapper < TEntity , TElement > > collectionMapping ,
210
+ Action < ICollectionElementRelation < TElement > > mapping )
198
211
{
199
212
RegisterSetMapping ( property , collectionMapping , mapping ) ;
200
213
}
@@ -222,8 +235,8 @@ protected void RegisterSetMapping<TElement>(Action<ISetPropertiesMapper<TEntity,
222
235
}
223
236
224
237
public void Bag < TElement > ( Expression < Func < TEntity , IEnumerable < TElement > > > property ,
225
- Action < IBagPropertiesMapper < TEntity , TElement > > collectionMapping ,
226
- Action < ICollectionElementRelation < TElement > > mapping )
238
+ Action < IBagPropertiesMapper < TEntity , TElement > > collectionMapping ,
239
+ Action < ICollectionElementRelation < TElement > > mapping )
227
240
{
228
241
RegisterBagMapping ( property , collectionMapping , mapping ) ;
229
242
}
@@ -250,8 +263,8 @@ protected void RegisterBagMapping<TElement>(Action<IBagPropertiesMapper<TEntity,
250
263
}
251
264
252
265
public void List < TElement > ( Expression < Func < TEntity , IEnumerable < TElement > > > property ,
253
- Action < IListPropertiesMapper < TEntity , TElement > > collectionMapping ,
254
- Action < ICollectionElementRelation < TElement > > mapping )
266
+ Action < IListPropertiesMapper < TEntity , TElement > > collectionMapping ,
267
+ Action < ICollectionElementRelation < TElement > > mapping )
255
268
{
256
269
RegisterListMapping ( property , collectionMapping , mapping ) ;
257
270
}
@@ -278,9 +291,9 @@ protected void RegisterListMapping<TElement>(Action<IListPropertiesMapper<TEntit
278
291
}
279
292
280
293
public void Map < TKey , TElement > ( Expression < Func < TEntity , IDictionary < TKey , TElement > > > property ,
281
- Action < IMapPropertiesMapper < TEntity , TKey , TElement > > collectionMapping ,
282
- Action < IMapKeyRelation < TKey > > keyMapping ,
283
- Action < ICollectionElementRelation < TElement > > mapping )
294
+ Action < IMapPropertiesMapper < TEntity , TKey , TElement > > collectionMapping ,
295
+ Action < IMapKeyRelation < TKey > > keyMapping ,
296
+ Action < ICollectionElementRelation < TElement > > mapping )
284
297
{
285
298
RegisterMapMapping ( property , collectionMapping , keyMapping , mapping ) ;
286
299
}
@@ -351,7 +364,7 @@ public void Set<TElement>(string notVisiblePropertyOrFieldName, Action<ISetPrope
351
364
if ( ! typeof ( TElement ) . Equals ( collectionElementType ) )
352
365
{
353
366
throw new MappingException ( string . Format ( "Wrong collection element type. For the property/field '{0}' of {1} was expected a collection of {2} but was {3}" ,
354
- notVisiblePropertyOrFieldName , typeof ( TEntity ) . FullName , typeof ( TElement ) . Name , collectionElementType . Name ) ) ;
367
+ notVisiblePropertyOrFieldName , typeof ( TEntity ) . FullName , typeof ( TElement ) . Name , collectionElementType . Name ) ) ;
355
368
}
356
369
MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
357
370
RegisterSetMapping < TElement > ( collectionMapping , mapping , member , memberOf ) ;
@@ -492,19 +505,6 @@ public void Any<TProperty>(string notVisiblePropertyOrFieldName, System.Type idT
492
505
RegisterAnyMapping < TProperty > ( mapping , idTypeOfMetaType , member , memberOf ) ;
493
506
}
494
507
495
- public void OneToOne < TProperty > ( string notVisiblePropertyOrFieldName , Action < IOneToOneMapper > mapping ) where TProperty : class
496
- {
497
- MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
498
- var propertyOrFieldType = member . GetPropertyOrFieldType ( ) ;
499
- if ( ! typeof ( TProperty ) . Equals ( propertyOrFieldType ) )
500
- {
501
- throw new MappingException ( string . Format ( "Wrong relation type. For the property/field '{0}' of {1} was expected a one-to-one with {2} but was {3}" ,
502
- notVisiblePropertyOrFieldName , typeof ( TEntity ) . FullName , typeof ( TProperty ) . Name , propertyOrFieldType . Name ) ) ;
503
- }
504
- MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
505
- RegisterOneToOneMapping < TProperty > ( mapping , member , memberOf ) ;
506
- }
507
-
508
508
public static MemberInfo GetPropertyOrFieldMatchingNameOrThrow ( string memberName )
509
509
{
510
510
var result = typeof ( TEntity ) . GetPropertyOrFieldMatchingName ( memberName ) ;
0 commit comments