Browse Source

Enable nullable annotations for Volo.Abp.ObjectMapping

pull/17108/head
liangshiwei 3 years ago
parent
commit
f0e6f60124
  1. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemotePermissionChecker.cs
  2. 2
      framework/src/Volo.Abp.ObjectMapping/Volo.Abp.ObjectMapping.csproj
  3. 6
      framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/DefaultObjectMapper.cs
  4. 8
      framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/ObjectMapperExtensions.cs

4
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<bool> IsGrantedAsync(ClaimsPrincipal claimsPrincipal, string name)
public async Task<bool> 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<MultiplePermissionGrantResult> IsGrantedAsync(ClaimsPrincipal claimsPrincipal, string[] names)
public async Task<MultiplePermissionGrantResult> IsGrantedAsync(ClaimsPrincipal? claimsPrincipal, string[] names)
{
/* This provider always works for the current principal. */
return await IsGrantedAsync(names);

2
framework/src/Volo.Abp.ObjectMapping/Volo.Abp.ObjectMapping.csproj

@ -5,6 +5,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.ObjectMapping</AssemblyName>
<PackageId>Volo.Abp.ObjectMapping</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

6
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())

8
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 })!;
}
}

Loading…
Cancel
Save