@@ -31,6 +31,13 @@ public ComponentElementCustomizer(IModelExplicitDeclarationsHolder explicitDecla
3131
3232 #region IComponentElementMapper<TComponent> Members
3333
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+
3441 public void Parent < TProperty > ( Expression < Func < TComponent , TProperty > > parent ) where TProperty : class
3542 {
3643 Parent ( parent , x => { } ) ;
@@ -68,6 +75,25 @@ public void Class<TConcrete>() where TConcrete : TComponent
6875 _customizersHolder . AddCustomizer ( typeof ( TComponent ) , ( IComponentAttributesMapper x ) => x . Class ( typeof ( TConcrete ) ) ) ;
6976 }
7077
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+
7197 public void Property < TProperty > ( Expression < Func < TComponent , TProperty > > property , Action < IPropertyMapper > mapping )
7298 {
7399 MemberInfo member = TypeExtensions . DecodeMemberAccessExpression ( property ) ;
@@ -92,6 +118,15 @@ public void Component<TNestedComponent>(Expression<Func<TComponent, TNestedCompo
92118 mapping ( new ComponentElementCustomizer < TNestedComponent > ( _explicitDeclarationsHolder , new PropertyPath ( _propertyPath , memberOf ) , _customizersHolder ) ) ;
93119 }
94120
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+
95130 public void ManyToOne < TProperty > ( Expression < Func < TComponent , TProperty > > property , Action < IManyToOneMapper > mapping ) where TProperty : class
96131 {
97132 MemberInfo member = TypeExtensions . DecodeMemberAccessExpression ( property ) ;
@@ -107,6 +142,20 @@ public void ManyToOne<TProperty>(Expression<Func<TComponent, TProperty>> propert
107142 ManyToOne ( property , x => { } ) ;
108143 }
109144
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+
110159 public void Access ( Accessor accessor )
111160 {
112161 _customizersHolder . AddCustomizer ( typeof ( TComponent ) , ( IComponentAttributesMapper x ) => x . Access ( accessor ) ) ;
0 commit comments