Skip to content

Commit 535d6b2

Browse files
Chris Martinezcommonsensesoftware
Chris Martinez
authored andcommitted
Update OData to support .NET Core 3.1
1 parent a82d3d1 commit 535d6b2

File tree

54 files changed

+731
-1387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+731
-1387
lines changed

samples/aspnetcore/ODataBasicSample/ODataBasicSample.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<RootNamespace>Microsoft.Examples</RootNamespace>
66
</PropertyGroup>
7-
8-
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.App" />
10-
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
11-
</ItemGroup>
127

138
<ItemGroup>
149
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.OData.Versioning\Microsoft.AspNetCore.OData.Versioning.csproj" />

samples/aspnetcore/ODataBasicSample/Startup.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.AspNet.OData.Builder;
55
using Microsoft.AspNet.OData.Extensions;
66
using Microsoft.AspNetCore.Builder;
7-
using Microsoft.AspNetCore.Hosting;
87
using Microsoft.Extensions.Configuration;
98
using Microsoft.Extensions.DependencyInjection;
109
using static Microsoft.AspNetCore.Mvc.CompatibilityVersion;
@@ -35,7 +34,7 @@ public void ConfigureServices( IServiceCollection services )
3534
}
3635

3736
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
38-
public void Configure( IApplicationBuilder app, IHostingEnvironment env, VersionedODataModelBuilder modelBuilder )
37+
public void Configure( IApplicationBuilder app, VersionedODataModelBuilder modelBuilder )
3938
{
4039
app.UseMvc(
4140
routeBuilder =>

samples/aspnetcore/SwaggerODataSample/Startup.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.AspNet.OData.Builder;
55
using Microsoft.AspNet.OData.Extensions;
66
using Microsoft.AspNetCore.Builder;
7-
using Microsoft.AspNetCore.Hosting;
87
using Microsoft.AspNetCore.Mvc.ApiExplorer;
98
using Microsoft.Extensions.DependencyInjection;
109
using Microsoft.Extensions.Options;
@@ -72,10 +71,9 @@ public void ConfigureServices( IServiceCollection services )
7271
/// Configures the application using the provided builder, hosting environment, and logging factory.
7372
/// </summary>
7473
/// <param name="app">The current application builder.</param>
75-
/// <param name="env">The current hosting environment.</param>
7674
/// <param name="modelBuilder">The <see cref="VersionedODataModelBuilder">model builder</see> used to create OData entity data models (EDMs).</param>
7775
/// <param name="provider">The API version descriptor provider used to enumerate defined API versions.</param>
78-
public void Configure( IApplicationBuilder app, IHostingEnvironment env, VersionedODataModelBuilder modelBuilder, IApiVersionDescriptionProvider provider )
76+
public void Configure( IApplicationBuilder app, VersionedODataModelBuilder modelBuilder, IApiVersionDescriptionProvider provider )
7977
{
8078
app.UseMvc(
8179
routeBuilder =>
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<RootNamespace>Microsoft.Examples</RootNamespace>
66
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(MSBuildThisFileName).xml</DocumentationFile>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.App" />
11-
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
1210
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
1311
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-*" />
1412
</ItemGroup>
@@ -17,4 +15,4 @@
1715
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.OData.Versioning.ApiExplorer\Microsoft.AspNetCore.OData.Versioning.ApiExplorer.csproj" />
1816
</ItemGroup>
1917

20-
</Project>
18+
</Project>

src/Common.OData.ApiExplorer/AspNet.OData/ClassProperty.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ internal ClassProperty( IServiceProvider services, IEdmOperationParameter parame
5050

5151
internal IReadOnlyList<CustomAttributeBuilder> Attributes { get; }
5252

53+
#if WEBAPI
5354
public override int GetHashCode() => ( Name.GetHashCode() * 397 ) ^ Type.GetHashCode();
54-
55+
#else
56+
public override int GetHashCode() => HashCode.Combine( Name, Type );
57+
#endif
5558
static IEnumerable<CustomAttributeBuilder> AttributesFromOperationParameter( IEdmOperationParameter parameter )
5659
{
5760
if ( parameter.Type.IsNullable )

src/Common.OData.ApiExplorer/AspNet.OData/ClassSignature.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal ClassSignature( Type originalType, IEnumerable<ClassProperty> propertie
3232

3333
attributeBuilders.AddRange( originalType.DeclaredAttributes() );
3434

35-
Name = originalType.FullName;
35+
Name = originalType.FullName!;
3636
Attributes = attributeBuilders.ToArray();
3737
Properties = properties.ToArray();
3838
ApiVersion = apiVersion;
@@ -58,7 +58,7 @@ internal ClassSignature( string name, IEnumerable<ClassProperty> properties, Api
5858

5959
public override int GetHashCode() => hashCode.Value;
6060

61-
public override bool Equals( object obj ) => obj is ClassSignature s && Equals( s );
61+
public override bool Equals( object? obj ) => obj is ClassSignature s && Equals( s );
6262

6363
public bool Equals( ClassSignature other ) => GetHashCode() == other?.GetHashCode();
6464

src/Common.OData.ApiExplorer/AspNet.OData/DefaultModelTypeBuilder.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public sealed class DefaultModelTypeBuilder : IModelTypeBuilder
2828
{
2929
static readonly Type IEnumerableOfT = typeof( IEnumerable<> );
3030
readonly ConcurrentDictionary<ApiVersion, ModuleBuilder> modules = new ConcurrentDictionary<ApiVersion, ModuleBuilder>();
31-
readonly ConcurrentDictionary<ApiVersion, IDictionary<EdmTypeKey, TypeInfo>> generatedEdmTypesPerVersion = new ConcurrentDictionary<ApiVersion, IDictionary<EdmTypeKey, TypeInfo>>();
31+
readonly ConcurrentDictionary<ApiVersion, IDictionary<EdmTypeKey, Type>> generatedEdmTypesPerVersion = new ConcurrentDictionary<ApiVersion, IDictionary<EdmTypeKey, Type>>();
3232

3333
/// <inheritdoc />
3434
public Type NewStructuredType( IEdmStructuredType structuredType, Type clrType, ApiVersion apiVersion, IEdmModel edmModel )
@@ -55,7 +55,7 @@ public Type NewActionParameters( IServiceProvider services, IEdmAction action, A
5555
return CreateTypeInfoFromSignature( moduleBuilder, signature );
5656
}
5757

58-
IDictionary<EdmTypeKey, TypeInfo> GenerateTypesForEdmModel( IEdmModel model, ApiVersion apiVersion )
58+
IDictionary<EdmTypeKey, Type> GenerateTypesForEdmModel( IEdmModel model, ApiVersion apiVersion )
5959
{
6060
ModuleBuilder NewModuleBuilder() => modules.GetOrAdd( apiVersion, CreateModuleForApiVersion );
6161

@@ -216,7 +216,7 @@ static Tuple<bool, bool> BuildSignatureProperties(
216216
return Tuple.Create( clrTypeMatchesEdmType, hasUnfinishedTypes );
217217
}
218218

219-
static TypeInfo ResolveType(
219+
static Type ResolveType(
220220
EdmTypeKey typeKey,
221221
Type clrType,
222222
bool clrTypeMatchesEdmType,
@@ -228,7 +228,7 @@ static TypeInfo ResolveType(
228228
var apiVersion = context.ApiVersion;
229229
var edmTypes = context.EdmTypes;
230230

231-
TypeInfo type;
231+
Type? type;
232232

233233
if ( clrTypeMatchesEdmType )
234234
{
@@ -272,7 +272,7 @@ static TypeInfo ResolveType(
272272
return type;
273273
}
274274

275-
static TypeInfo CreateTypeInfoFromSignature( ModuleBuilder moduleBuilder, ClassSignature @class ) => CreateTypeBuilderFromSignature( moduleBuilder, @class ).CreateTypeInfo();
275+
static Type CreateTypeInfoFromSignature( ModuleBuilder moduleBuilder, ClassSignature @class ) => CreateTypeBuilderFromSignature( moduleBuilder, @class ).CreateType()!;
276276

277277
static TypeBuilder CreateTypeBuilderFromSignature( ModuleBuilder moduleBuilder, ClassSignature @class )
278278
{
@@ -297,7 +297,7 @@ static TypeBuilder CreateTypeBuilderFromSignature( ModuleBuilder moduleBuilder,
297297
return typeBuilder;
298298
}
299299

300-
static IDictionary<EdmTypeKey, TypeInfo> ResolveDependencies( BuilderContext context )
300+
static IDictionary<EdmTypeKey, Type> ResolveDependencies( BuilderContext context )
301301
{
302302
var edmTypes = context.EdmTypes;
303303
var dependencies = context.Dependencies;
@@ -323,7 +323,7 @@ static IDictionary<EdmTypeKey, TypeInfo> ResolveDependencies( BuilderContext con
323323

324324
if ( edmTypes[key] is TypeBuilder typeBuilder )
325325
{
326-
edmTypes[key] = typeBuilder.CreateTypeInfo();
326+
edmTypes[key] = typeBuilder.CreateTypeInfo()!;
327327
}
328328
}
329329

@@ -387,7 +387,7 @@ internal BuilderContext( IEdmModel edmModel, ApiVersion apiVersion, Func<ModuleB
387387

388388
internal IEdmModel EdmModel { get; }
389389

390-
internal IDictionary<EdmTypeKey, TypeInfo> EdmTypes { get; } = new Dictionary<EdmTypeKey, TypeInfo>();
390+
internal IDictionary<EdmTypeKey, Type> EdmTypes { get; } = new Dictionary<EdmTypeKey, Type>();
391391

392392
internal ISet<EdmTypeKey> VisitedEdmTypes { get; } = new HashSet<EdmTypeKey>();
393393

src/Common.OData.ApiExplorer/AspNet.OData/EdmTypeKey.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ internal EdmTypeKey( IEdmTypeReference type, ApiVersion apiVersion ) =>
2929

3030
public bool Equals( EdmTypeKey other ) => hashCode == other.hashCode;
3131

32-
static int ComputeHash( string fullName, ApiVersion apiVersion ) =>
33-
( fullName.GetHashCode() * 397 ) ^ apiVersion.GetHashCode();
32+
#if WEBAPI
33+
static int ComputeHash( string fullName, ApiVersion apiVersion ) => ( fullName.GetHashCode() * 397 ) ^ apiVersion.GetHashCode();
34+
#else
35+
static int ComputeHash( string fullName, ApiVersion apiVersion ) => HashCode.Combine( fullName, apiVersion );
36+
#endif
3437
}
3538
}

src/Common.OData.ApiExplorer/AspNet.OData/Routing/ODataRouteBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,14 +659,14 @@ sealed class TypeComparer : IEqualityComparer<Type>
659659

660660
public int GetHashCode( Type obj )
661661
{
662-
if ( obj.BaseType.Equals( typeof( ValueType ) ) || obj.BaseType.Equals( typeof( Array ) ) )
662+
if ( obj.BaseType == null || obj.BaseType.Equals( typeof( ValueType ) ) || obj.BaseType.Equals( typeof( Array ) ) )
663663
{
664664
return obj.GetHashCode();
665665
}
666666

667667
var baseType = typeof( object );
668668

669-
while ( !obj.BaseType.Equals( baseType ) )
669+
while ( obj.BaseType != null && !obj.BaseType.Equals( baseType ) )
670670
{
671671
obj = obj.BaseType;
672672
}

src/Common.OData.ApiExplorer/AspNet.OData/TypeExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ internal static IEnumerable<CustomAttributeBuilder> DeclaredAttributes( this Mem
103103
if ( argument.IsField )
104104
{
105105
namedFields.Add( (FieldInfo) argument.MemberInfo );
106-
fieldValues.Add( argument.TypedValue.Value );
106+
fieldValues.Add( argument.TypedValue.Value! );
107107
}
108108
else
109109
{
110110
namedProperties.Add( (PropertyInfo) argument.MemberInfo );
111-
propertyValues.Add( argument.TypedValue.Value );
111+
propertyValues.Add( argument.TypedValue.Value! );
112112
}
113113
}
114114

@@ -278,7 +278,7 @@ internal static bool IsEnumerable( this Type type, out Type? itemType )
278278

279279
static bool IsSingleResult( this Type type ) => type.Is( SingleResultOfT );
280280

281-
static bool IsODataValue( this Type type )
281+
static bool IsODataValue( this Type? type )
282282
{
283283
while ( type != null )
284284
{

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#endif
1414
using static System.Globalization.CultureInfo;
1515
using static System.String;
16+
#if !WEBAPI
17+
using static System.StringComparison;
18+
#endif
1619

1720
static class EdmExtensions
1821
{
@@ -32,7 +35,7 @@ static class EdmExtensions
3235
}
3336

3437
var element = (IEdmSchemaType) edmType;
35-
var annotationValue = edmModel.GetAnnotationValue<ClrTypeAnnotation>(element);
38+
var annotationValue = edmModel.GetAnnotationValue<ClrTypeAnnotation>( element );
3639

3740
if ( annotationValue != null )
3841
{
@@ -59,17 +62,29 @@ static class EdmExtensions
5962
case "Edm.DateTime":
6063
case "Edm.DateTimeOffset":
6164
case "Edm.Guid":
65+
#if WEBAPI
6266
return Type.GetType( edmFullName.Replace( "Edm", "System" ), throwOnError: true );
67+
#else
68+
return Type.GetType( edmFullName.Replace( "Edm", "System", Ordinal ), throwOnError: true );
69+
#endif
6370
case "Edm.Duration":
6471
return typeof( TimeSpan );
6572
case "Edm.Binary":
6673
return typeof( byte[] );
6774
case "Edm.Geography":
6875
case "Edm.Geometry":
76+
#if WEBAPI
6977
return Type.GetType( edmFullName.Replace( "Edm", "Microsoft.Spatial" ), throwOnError: true );
78+
#else
79+
return Type.GetType( edmFullName.Replace( "Edm", "Microsoft.Spatial", Ordinal ), throwOnError: true );
80+
#endif
7081
case "Edm.Date":
7182
case "Edm.TimeOfDay":
83+
#if WEBAPI
7284
return Type.GetType( edmFullName.Replace( "Edm", "Microsoft.OData.Edm" ), throwOnError: true );
85+
#else
86+
return Type.GetType( edmFullName.Replace( "Edm", "Microsoft.OData.Edm", Ordinal ), throwOnError: true );
87+
#endif
7388
}
7489

7590
return null;

src/Common/ApiVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public static ApiVersion Parse( string text )
222222
/// <param name="text">The text to parse.</param>
223223
/// <param name="version">The parsed <see cref="ApiVersion">API version</see>, if the operation is successful.</param>
224224
/// <returns>True if the operation succeeded; otherwise false.</returns>
225-
#if NETAPPCORE3_0
225+
#if NETAPPCORE3_1
226226
public static bool TryParse( string text, [NotNullWhen( true )] out ApiVersion? version )
227227
#else
228228
public static bool TryParse( string? text, out ApiVersion? version )

src/Common/CollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Mvc
1818

1919
static partial class CollectionExtensions
2020
{
21-
#if NETAPPCORE3_0
21+
#if NETAPPCORE3_1
2222
internal static bool TryGetValue<TKey, TValue>( this IDictionary<TKey, object?> dictionary, TKey key, [NotNullWhen(true)] out TValue value ) where TKey : notnull
2323
#else
2424
internal static bool TryGetValue<TKey, TValue>( this IDictionary<TKey, object?> dictionary, TKey key, out TValue value ) where TKey : notnull

src/Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer/ApiDescriptionExtensions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ public static bool TryUpdateRelativePathAndRemoveApiVersionParameter( this ApiDe
8282
var relativePath = apiDescription.RelativePath;
8383
var token = '{' + parameter.Name + '}';
8484
var value = apiDescription.GetApiVersion().ToString( options.SubstitutionFormat, InvariantCulture );
85-
#if NETSTANDARD2_0
86-
var newRelativePath = relativePath.Replace( token, value );
87-
#else
8885
var newRelativePath = relativePath.Replace( token, value, StringComparison.Ordinal );
89-
#endif
9086

9187
if ( relativePath == newRelativePath )
9288
{

src/Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer/Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer.csproj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>4.1.0</VersionPrefix>
4+
<VersionPrefix>4.1.1</VersionPrefix>
55
<AssemblyVersion>4.1.0.0</AssemblyVersion>
6-
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
7-
<NETStandardImplicitPackageVersion>2.0.0-*</NETStandardImplicitPackageVersion>
8-
<NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion>
6+
<TargetFramework>netcoreapp3.1</TargetFramework>
97
<AssemblyTitle>Microsoft ASP.NET Core API Versioning</AssemblyTitle>
108
<Description>ASP.NET Core MVC API explorer functionality for discovering metadata such as the list of API-versioned controllers and actions, and their URLs and allowed HTTP methods.</Description>
119
<RootNamespace>Microsoft.AspNetCore.Mvc.ApiExplorer</RootNamespace>
@@ -16,10 +14,6 @@
1614
<ProjectReference Include="..\Microsoft.AspNetCore.Mvc.Versioning\Microsoft.AspNetCore.Mvc.Versioning.csproj" />
1715
</ItemGroup>
1816

19-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
20-
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="[2.2.0,3.0.0)" />
21-
</ItemGroup>
22-
2317
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
2418
<Import Project="..\Common.ApiExplorer\Common.ApiExplorer.projitems" Label="Shared" />
2519

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Add support for .NET Core 3.1
1+
Drop support for .NET Core 2.2

src/Microsoft.AspNetCore.Mvc.Versioning/Microsoft.AspNetCore.Mvc.Versioning.csproj

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>4.1.0</VersionPrefix>
4+
<VersionPrefix>4.1.1</VersionPrefix>
55
<AssemblyVersion>4.1.0.0</AssemblyVersion>
6-
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
7-
<NETStandardImplicitPackageVersion>2.0.0-*</NETStandardImplicitPackageVersion>
8-
<NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion>
6+
<TargetFramework>netcoreapp3.1</TargetFramework>
97
<AssemblyTitle>Microsoft ASP.NET Core API Versioning</AssemblyTitle>
108
<Description>A service API versioning library for Microsoft ASP.NET Core.</Description>
119
<RootNamespace>Microsoft.AspNetCore.Mvc</RootNamespace>
1210
<PackageTags>Microsoft;AspNet;AspNetCore;Versioning</PackageTags>
1311
</PropertyGroup>
1412

15-
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
16-
<FrameworkReference Include="Microsoft.AspNetCore.App" />
17-
</ItemGroup>
18-
19-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
20-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="[2.2.0,3.0.0)" />
21-
</ItemGroup>
22-
2313
<ItemGroup>
24-
<Compile Update="Routing\ApiVersionMatcherPolicy.netcoreapp3.1.cs" DependentUpon="Routing\ApiVersionMatcherPolicy.cs" />
25-
<Compile Update="Routing\ApiVersionMatcherPolicy.netstandard2.0.cs" DependentUpon="Routing\ApiVersionMatcherPolicy.cs" />
26-
<Compile Update="Versioning\ApiVersionActionSelector.netcoreapp3.1.cs" DependentUpon="Versioning\ApiVersionActionSelector.cs" />
27-
<Compile Update="Versioning\ApiVersionActionSelector.netstandard2.0.cs" DependentUpon="Versioning\ApiVersionActionSelector.cs" />
14+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
2815
</ItemGroup>
2916

3017
<Import Project="..\Common\Common.projitems" Label="Shared" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Add support for .NET Core 3.1
1+
Drop support for .NET Core 2.2

0 commit comments

Comments
 (0)