Browse Source

Enable nullable annotations for Volo.Abp.FluentValidation

pull/17108/head
liangshiwei 3 years ago
parent
commit
a8ad895c6f
  1. 2
      framework/src/Volo.Abp.FluentValidation/Volo.Abp.FluentValidation.csproj
  2. 6
      framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/AbpFluentValidationConventionalRegistrar.cs
  3. 2
      framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/FluentObjectValidationContributor.cs

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

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

6
framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/AbpFluentValidationConventionalRegistrar.cs

@ -24,11 +24,11 @@ public class AbpFluentValidationConventionalRegistrar : DefaultConventionalRegis
{ {
return new List<Type>() return new List<Type>()
{ {
typeof(IValidator<>).MakeGenericType(GetFirstGenericArgumentOrNull(type, 1)) typeof(IValidator<>).MakeGenericType(GetFirstGenericArgumentOrNull(type, 1)!)
}; };
} }
private static Type GetFirstGenericArgumentOrNull(Type type, int depth) private static Type? GetFirstGenericArgumentOrNull(Type type, int depth)
{ {
const int maxFindDepth = 8; const int maxFindDepth = 8;
@ -42,6 +42,6 @@ public class AbpFluentValidationConventionalRegistrar : DefaultConventionalRegis
return type.GetGenericArguments()[0]; return type.GetGenericArguments()[0];
} }
return GetFirstGenericArgumentOrNull(type.BaseType, depth + 1); return GetFirstGenericArgumentOrNull(type.BaseType!, depth + 1);
} }
} }

2
framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/FluentObjectValidationContributor.cs

@ -29,7 +29,7 @@ public class FluentObjectValidationContributor : IObjectValidationContributor, I
var result = await validator.ValidateAsync((IValidationContext)Activator.CreateInstance( var result = await validator.ValidateAsync((IValidationContext)Activator.CreateInstance(
typeof(ValidationContext<>).MakeGenericType(context.ValidatingObject.GetType()), typeof(ValidationContext<>).MakeGenericType(context.ValidatingObject.GetType()),
context.ValidatingObject)); context.ValidatingObject)!);
if (!result.IsValid) if (!result.IsValid)
{ {

Loading…
Cancel
Save