@@ -21,13 +21,13 @@ sealed class ODataRouteBuilder
2121 {
2222 static readonly Type ODataQueryOptionsType = typeof ( ODataQueryOptions ) ;
2323 static readonly Type ODataActionParametersType = typeof ( ODataActionParameters ) ;
24- static readonly Type GeographyType = typeof ( Spatial . Geography ) ;
25- static readonly Type GeometryType = typeof ( Spatial . Geometry ) ;
26- static readonly Dictionary < Type , string > quotedTypes = new Dictionary < Type , string > ( )
24+ static readonly Dictionary < Type , string > quotedTypes = new Dictionary < Type , string > ( new TypeComparer ( ) )
2725 {
2826 [ typeof ( string ) ] = string . Empty ,
2927 [ typeof ( TimeSpan ) ] = "duration" ,
3028 [ typeof ( byte [ ] ) ] = "binary" ,
29+ [ typeof ( Spatial . Geography ) ] = "geography" ,
30+ [ typeof ( Spatial . Geometry ) ] = "geometry" ,
3131 } ;
3232
3333 internal ODataRouteBuilder ( ODataRouteBuilderContext context )
@@ -220,20 +220,23 @@ void ExpandParameterTemplate( StringBuilder template, IEdmTypeReference typeRefe
220220 Contract . Requires ( ! IsNullOrEmpty ( name ) ) ;
221221
222222 var typeDef = typeReference . Definition ;
223+ var offset = template . Length ;
223224
224225 template . Append ( "{" ) ;
225226 template . Append ( name ) ;
226227 template . Append ( "}" ) ;
227228
228229 if ( typeDef . TypeKind == EdmTypeKind . Enum )
229230 {
230- template . Insert ( 0 , ' \' ' ) ;
231+ var fullName = typeReference . FullName ( ) ;
231232
232233 if ( ! Context . AllowUnqualifiedEnum )
233234 {
234- template . Insert ( 0 , typeReference . FullName ( ) ) ;
235+ template . Insert ( offset , fullName ) ;
236+ offset += fullName . Length ;
235237 }
236238
239+ template . Insert ( offset , '\' ' ) ;
237240 template . Append ( '\' ' ) ;
238241 return ;
239242 }
@@ -242,18 +245,9 @@ void ExpandParameterTemplate( StringBuilder template, IEdmTypeReference typeRefe
242245
243246 if ( quotedTypes . TryGetValue ( type , out var prefix ) )
244247 {
245- template . Insert ( 0 , '\' ' ) ;
246- template . Insert ( 0 , prefix ) ;
247- template . Append ( '\' ' ) ;
248- }
249- else if ( GeographyType . IsAssignableFrom ( type ) )
250- {
251- template . Insert ( 0 , "geography'" ) ;
252- template . Append ( '\' ' ) ;
253- }
254- else if ( GeometryType . IsAssignableFrom ( type ) )
255- {
256- template . Insert ( 0 , "geometry'" ) ;
248+ template . Insert ( offset , prefix ) ;
249+ offset += prefix . Length ;
250+ template . Insert ( offset , '\' ' ) ;
257251 template . Append ( '\' ' ) ;
258252 }
259253 }
@@ -364,5 +358,27 @@ static bool IsFunctionParameter( IEdmOperation operation, ApiParameterDescriptio
364358
365359 return operation . Parameters . Any ( p => p . Name . Equals ( name , OrdinalIgnoreCase ) ) ;
366360 }
361+
362+ sealed class TypeComparer : IEqualityComparer < Type >
363+ {
364+ public bool Equals ( Type x , Type y ) => x . IsAssignableFrom ( y ) ;
365+
366+ public int GetHashCode ( Type obj )
367+ {
368+ if ( obj . BaseType . Equals ( typeof ( ValueType ) ) || obj . BaseType . Equals ( typeof ( Array ) ) )
369+ {
370+ return obj . GetHashCode ( ) ;
371+ }
372+
373+ var baseType = typeof ( object ) ;
374+
375+ while ( ! obj . BaseType . Equals ( baseType ) )
376+ {
377+ obj = obj . BaseType ;
378+ }
379+
380+ return obj . GetHashCode ( ) ;
381+ }
382+ }
367383 }
368384}
0 commit comments