Skip to content

Commit a004cd2

Browse files
Use fully-qualified assembly name for type resolution. Fixes #854
1 parent 428b036 commit a004cd2

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/Common/src/Common.OData.ApiExplorer/Microsoft.OData.Edm/EdmExtensions.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Microsoft.OData.Edm;
77
#else
88
using Microsoft.OData.ModelBuilder;
99
#endif
10-
using static System.StringComparison;
10+
using System.Runtime.CompilerServices;
1111

1212
internal static class EdmExtensions
1313
{
@@ -41,11 +41,24 @@ internal static class EdmExtensions
4141
{
4242
"Edm.String" or "Edm.Byte" or "Edm.SByte" or "Edm.Int16" or "Edm.Int32" or "Edm.Int64" or
4343
"Edm.Double" or "Edm.Single" or "Edm.Boolean" or "Edm.Decimal" or "Edm.DateTime" or "Edm.DateTimeOffset" or
44-
"Edm.Guid" => Type.GetType( edmFullName.Replace( "Edm", "System", Ordinal ), ThrowOnError ),
44+
"Edm.Guid" => Type.GetType( Requalify( edmFullName, "System" ), ThrowOnError ),
4545
"Edm.Duration" => typeof( TimeSpan ),
4646
"Edm.Binary" => typeof( byte[] ),
47-
"Edm.Geography" or "Edm.Geometry" => Type.GetType( edmFullName.Replace( "Edm", "Microsoft.Spatial", Ordinal ), ThrowOnError ),
48-
"Edm.Date" or "Edm.TimeOfDay" => Type.GetType( edmFullName.Replace( "Edm", "Microsoft.OData.Edm", Ordinal ), ThrowOnError ),
47+
"Edm.Geography" or "Edm.Geometry" => GetTypeFromAssembly( edmFullName, "Microsoft.Spatial" ),
48+
"Edm.Date" or "Edm.TimeOfDay" => GetTypeFromAssembly( edmFullName, "Microsoft.OData.Edm" ),
4949
_ => null,
5050
};
51+
52+
[MethodImpl( MethodImplOptions.AggressiveInlining )]
53+
#if NETFRAMEWORK
54+
private static string Requalify( string edmFullName, string @namespace ) => @namespace + edmFullName.Substring( 3 );
55+
#else
56+
private static string Requalify( string edmFullName, string @namespace ) => string.Concat( @namespace.AsSpan(), edmFullName.AsSpan().Slice( 3 ) );
57+
#endif
58+
59+
private static Type? GetTypeFromAssembly( string edmFullName, string assemblyName )
60+
{
61+
var typeName = Requalify( edmFullName, assemblyName ) + "," + assemblyName;
62+
return Type.GetType( typeName, ThrowOnError );
63+
}
5164
}

0 commit comments

Comments
 (0)