@@ -31,6 +31,13 @@ public ComponentElementCustomizer(IModelExplicitDeclarationsHolder explicitDecla
31
31
32
32
#region IComponentElementMapper<TComponent> Members
33
33
34
+ public void Parent ( string notVisiblePropertyOrFieldName , Action < IComponentParentMapper > parentMapping )
35
+ {
36
+ MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
37
+ _customizersHolder . AddCustomizer ( typeof ( TComponent ) , ( IComponentAttributesMapper x ) => x . Parent ( member , parentMapping ) ) ;
38
+ _explicitDeclarationsHolder . AddAsPersistentMember ( member ) ;
39
+ }
40
+
34
41
public void Parent < TProperty > ( Expression < Func < TComponent , TProperty > > parent ) where TProperty : class
35
42
{
36
43
Parent ( parent , x => { } ) ;
@@ -68,6 +75,25 @@ public void Class<TConcrete>() where TConcrete : TComponent
68
75
_customizersHolder . AddCustomizer ( typeof ( TComponent ) , ( IComponentAttributesMapper x ) => x . Class ( typeof ( TConcrete ) ) ) ;
69
76
}
70
77
78
+ public void Property ( string notVisiblePropertyOrFieldName , Action < IPropertyMapper > mapping )
79
+ {
80
+ MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
81
+ MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TComponent ) ) ;
82
+ _customizersHolder . AddCustomizer ( new PropertyPath ( _propertyPath , member ) , mapping ) ;
83
+ _explicitDeclarationsHolder . AddAsProperty ( memberOf ) ;
84
+ }
85
+
86
+ public static MemberInfo GetPropertyOrFieldMatchingNameOrThrow ( string memberName )
87
+ {
88
+ var result = typeof ( TComponent ) . GetPropertyOrFieldMatchingName ( memberName ) ;
89
+ if ( result == null )
90
+ {
91
+ throw new MappingException ( string . Format ( "Member not found. The member '{0}' does not exists in type {1}" , memberName , typeof ( TComponent ) . FullName ) ) ;
92
+ }
93
+ return result ;
94
+ }
95
+
96
+
71
97
public void Property < TProperty > ( Expression < Func < TComponent , TProperty > > property , Action < IPropertyMapper > mapping )
72
98
{
73
99
MemberInfo member = TypeExtensions . DecodeMemberAccessExpression ( property ) ;
@@ -92,6 +118,15 @@ public void Component<TNestedComponent>(Expression<Func<TComponent, TNestedCompo
92
118
mapping ( new ComponentElementCustomizer < TNestedComponent > ( _explicitDeclarationsHolder , new PropertyPath ( _propertyPath , memberOf ) , _customizersHolder ) ) ;
93
119
}
94
120
121
+ public void Component < TNestedComponent > ( string notVisiblePropertyOrFieldName , Action < IComponentElementMapper < TNestedComponent > > mapping )
122
+ where TNestedComponent : class
123
+ {
124
+ MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
125
+ mapping ( new ComponentElementCustomizer < TNestedComponent > ( _explicitDeclarationsHolder , new PropertyPath ( _propertyPath , member ) , _customizersHolder ) ) ;
126
+ MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TComponent ) ) ;
127
+ mapping ( new ComponentElementCustomizer < TNestedComponent > ( _explicitDeclarationsHolder , new PropertyPath ( _propertyPath , memberOf ) , _customizersHolder ) ) ;
128
+ }
129
+
95
130
public void ManyToOne < TProperty > ( Expression < Func < TComponent , TProperty > > property , Action < IManyToOneMapper > mapping ) where TProperty : class
96
131
{
97
132
MemberInfo member = TypeExtensions . DecodeMemberAccessExpression ( property ) ;
@@ -107,6 +142,20 @@ public void ManyToOne<TProperty>(Expression<Func<TComponent, TProperty>> propert
107
142
ManyToOne ( property , x => { } ) ;
108
143
}
109
144
145
+ public void ManyToOne < TProperty > ( string notVisiblePropertyOrFieldName , Action < IManyToOneMapper > mapping ) where TProperty : class
146
+ {
147
+ MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
148
+ var propertyOrFieldType = member . GetPropertyOrFieldType ( ) ;
149
+ if ( ! typeof ( TProperty ) . Equals ( propertyOrFieldType ) )
150
+ {
151
+ throw new MappingException ( string . Format ( "Wrong relation type. For the property/field '{0}' of {1} was expected a many-to-one with {2} but was {3}" ,
152
+ notVisiblePropertyOrFieldName , typeof ( TComponent ) . FullName , typeof ( TProperty ) . Name , propertyOrFieldType . Name ) ) ;
153
+ }
154
+ MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TComponent ) ) ;
155
+ _explicitDeclarationsHolder . AddAsManyToOneRelation ( member ) ;
156
+ _explicitDeclarationsHolder . AddAsManyToOneRelation ( memberOf ) ;
157
+ }
158
+
110
159
public void Access ( Accessor accessor )
111
160
{
112
161
_customizersHolder . AddCustomizer ( typeof ( TComponent ) , ( IComponentAttributesMapper x ) => x . Access ( accessor ) ) ;
0 commit comments