From f0e6f601241650f871bc485b5822fa35d2272209 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 13 Jul 2023 10:49:53 +0800 Subject: [PATCH] Enable nullable annotations for Volo.Abp.ObjectMapping --- .../Abp/AspNetCore/Mvc/Client/RemotePermissionChecker.cs | 4 ++-- .../Volo.Abp.ObjectMapping/Volo.Abp.ObjectMapping.csproj | 2 ++ .../Volo/Abp/ObjectMapping/DefaultObjectMapper.cs | 6 +++--- .../Volo/Abp/ObjectMapping/ObjectMapperExtensions.cs | 8 ++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemotePermissionChecker.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemotePermissionChecker.cs index 3274c5010c..a2fca1f127 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemotePermissionChecker.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemotePermissionChecker.cs @@ -21,7 +21,7 @@ public class RemotePermissionChecker : IPermissionChecker, ITransientDependency return configuration.Auth.GrantedPolicies.ContainsKey(name); } - public async Task IsGrantedAsync(ClaimsPrincipal claimsPrincipal, string name) + public async Task IsGrantedAsync(ClaimsPrincipal? claimsPrincipal, string name) { /* This provider always works for the current principal. */ return await IsGrantedAsync(name); @@ -41,7 +41,7 @@ public class RemotePermissionChecker : IPermissionChecker, ITransientDependency return result; } - public async Task IsGrantedAsync(ClaimsPrincipal claimsPrincipal, string[] names) + public async Task IsGrantedAsync(ClaimsPrincipal? claimsPrincipal, string[] names) { /* This provider always works for the current principal. */ return await IsGrantedAsync(names); diff --git a/framework/src/Volo.Abp.ObjectMapping/Volo.Abp.ObjectMapping.csproj b/framework/src/Volo.Abp.ObjectMapping/Volo.Abp.ObjectMapping.csproj index 14d738ab6c..db27274909 100644 --- a/framework/src/Volo.Abp.ObjectMapping/Volo.Abp.ObjectMapping.csproj +++ b/framework/src/Volo.Abp.ObjectMapping/Volo.Abp.ObjectMapping.csproj @@ -5,6 +5,8 @@ netstandard2.0;netstandard2.1;net7.0 + enable + Nullable Volo.Abp.ObjectMapping Volo.Abp.ObjectMapping $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; diff --git a/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/DefaultObjectMapper.cs b/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/DefaultObjectMapper.cs index 4c57630a44..7048d183c7 100644 --- a/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/DefaultObjectMapper.cs +++ b/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/DefaultObjectMapper.cs @@ -36,7 +36,7 @@ public class DefaultObjectMapper : IObjectMapper, ITransientDependency { if (source == null) { - return default; + return default!; } using (var scope = ServiceProvider.CreateScope()) @@ -60,7 +60,7 @@ public class DefaultObjectMapper : IObjectMapper, ITransientDependency //TODO: Check if TDestination has a proper constructor which takes TSource //TODO: Check if TDestination has an empty constructor (in this case, use MapFrom) - return (TDestination)Activator.CreateInstance(typeof(TDestination), source); + return (TDestination)Activator.CreateInstance(typeof(TDestination), source)!; } catch { @@ -75,7 +75,7 @@ public class DefaultObjectMapper : IObjectMapper, ITransientDependency { if (source == null) { - return default; + return default!; } using (var scope = ServiceProvider.CreateScope()) diff --git a/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/ObjectMapperExtensions.cs b/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/ObjectMapperExtensions.cs index a99f977002..9a501fe35e 100644 --- a/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/ObjectMapperExtensions.cs +++ b/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/ObjectMapperExtensions.cs @@ -5,8 +5,8 @@ namespace Volo.Abp.ObjectMapping; public static class ObjectMapperExtensions { - private static readonly MethodInfo MapToNewObjectMethod; - private static readonly MethodInfo MapToExistingObjectMethod; + private static readonly MethodInfo MapToNewObjectMethod = default!; + private static readonly MethodInfo MapToExistingObjectMethod = default!; static ObjectMapperExtensions() { @@ -32,13 +32,13 @@ public static class ObjectMapperExtensions { return MapToNewObjectMethod .MakeGenericMethod(sourceType, destinationType) - .Invoke(objectMapper, new[] { source }); + .Invoke(objectMapper, new[] { source })!; } public static object Map(this IObjectMapper objectMapper, Type sourceType, Type destinationType, object source, object destination) { return MapToExistingObjectMethod .MakeGenericMethod(sourceType, destinationType) - .Invoke(objectMapper, new[] { source, destination }); + .Invoke(objectMapper, new[] { source, destination })!; } }