77using System . Diagnostics . Contracts ;
88using System . Linq ;
99using System . Reflection ;
10+ using System . Runtime . CompilerServices ;
1011using Microsoft . AspNet . OData . Common ;
1112
1213namespace Microsoft . AspNet . OData . Builder
@@ -525,8 +526,8 @@ private void VerifyBindingPath(NavigationPropertyConfiguration navigationConfigu
525526 Contract . Assert ( navigationConfiguration != null ) ;
526527 Contract . Assert ( bindingPath != null ) ;
527528
528- PropertyInfo navigation = bindingPath . Last ( ) as PropertyInfo ;
529- if ( navigation == null || navigation != navigationConfiguration . PropertyInfo )
529+ MemberInfo navigation = bindingPath . Last ( ) as MemberInfo ;
530+ if ( navigation == null || navigation != navigationConfiguration . PropertyInfo . MemberInfo )
530531 {
531532 throw Error . Argument ( "navigationConfiguration" , SRResources . NavigationPropertyBindingPathIsNotValid ,
532533 bindingPath . ConvertBindingPath ( ) , navigationConfiguration . Name ) ;
@@ -552,13 +553,25 @@ private static Type VerifyBindingSegment(Type current, MemberInfo info)
552553 return derivedType . BaseType ;
553554 }
554555
556+ Type declaringType = null ;
557+ Type propertyType = null ;
555558 PropertyInfo propertyInfo = info as PropertyInfo ;
556- if ( propertyInfo == null )
559+ MethodInfo methodInfo = info as MethodInfo ;
560+ if ( propertyInfo != null )
561+ {
562+ declaringType = info . DeclaringType ;
563+ propertyType = propertyInfo . PropertyType ;
564+ }
565+ else if ( methodInfo != null && methodInfo . GetCustomAttribute < ExtensionAttribute > ( ) != null )
566+ {
567+ declaringType = methodInfo . GetParameters ( ) . First ( ) . ParameterType ;
568+ propertyType = methodInfo . ReturnType ;
569+ }
570+ else
557571 {
558572 throw Error . NotSupported ( SRResources . NavigationPropertyBindingPathNotSupported , info . Name , info . MemberType ) ;
559573 }
560574
561- Type declaringType = propertyInfo . DeclaringType ;
562575 if ( declaringType == null ||
563576 ! ( declaringType . IsAssignableFrom ( current ) || current . IsAssignableFrom ( declaringType ) ) )
564577 {
@@ -567,12 +580,12 @@ private static Type VerifyBindingSegment(Type current, MemberInfo info)
567580 }
568581
569582 Type elementType ;
570- if ( TypeHelper . IsCollection ( propertyInfo . PropertyType , out elementType ) )
583+ if ( TypeHelper . IsCollection ( propertyType , out elementType ) )
571584 {
572585 return elementType ;
573586 }
574587
575- return propertyInfo . PropertyType ;
588+ return propertyType ;
576589 }
577590 }
578591}
0 commit comments