Skip to content

Commit 535d6b2

Browse files
Chris Martinezcommonsensesoftware
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
{

0 commit comments

Comments
 (0)