Browse Source

Enable nullable annotations for Volo.Abp.GlobalFeatures

pull/17108/head
liangshiwei 3 years ago
parent
commit
aeadf8bb09
  1. 2
      framework/src/Volo.Abp.GlobalFeatures/Volo.Abp.GlobalFeatures.csproj
  2. 4
      framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/AbpGlobalFeatureNotEnabledException.cs
  3. 2
      framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureHelper.cs
  4. 4
      framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureInterceptor.cs
  5. 6
      framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeaturesSimpleStateCheckerSerializerContributor.cs
  6. 6
      framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/RequiresGlobalFeatureAttribute.cs

2
framework/src/Volo.Abp.GlobalFeatures/Volo.Abp.GlobalFeatures.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.GlobalFeatures</AssemblyName> <AssemblyName>Volo.Abp.GlobalFeatures</AssemblyName>
<PackageId>Volo.Abp.GlobalFeatures</PackageId> <PackageId>Volo.Abp.GlobalFeatures</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> <AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

4
framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/AbpGlobalFeatureNotEnabledException.cs

@ -6,9 +6,9 @@ namespace Volo.Abp.GlobalFeatures;
[Serializable] [Serializable]
public class AbpGlobalFeatureNotEnabledException : AbpException, IHasErrorCode public class AbpGlobalFeatureNotEnabledException : AbpException, IHasErrorCode
{ {
public string Code { get; } public string? Code { get; }
public AbpGlobalFeatureNotEnabledException(string message = null, string code = null, Exception innerException = null) public AbpGlobalFeatureNotEnabledException(string? message = null, string? code = null, Exception? innerException = null)
: base(message, innerException) : base(message, innerException)
{ {
Code = code; Code = code;

2
framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureHelper.cs

@ -5,7 +5,7 @@ namespace Volo.Abp.GlobalFeatures;
public static class GlobalFeatureHelper public static class GlobalFeatureHelper
{ {
public static bool IsGlobalFeatureEnabled(Type type, out RequiresGlobalFeatureAttribute attribute) public static bool IsGlobalFeatureEnabled(Type type, out RequiresGlobalFeatureAttribute? attribute)
{ {
attribute = ReflectionHelper.GetSingleAttributeOrDefault<RequiresGlobalFeatureAttribute>(type); attribute = ReflectionHelper.GetSingleAttributeOrDefault<RequiresGlobalFeatureAttribute>(type);
return attribute == null || GlobalFeatureManager.Instance.IsEnabled(attribute.GetFeatureName()); return attribute == null || GlobalFeatureManager.Instance.IsEnabled(attribute.GetFeatureName());

4
framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureInterceptor.cs

@ -18,8 +18,8 @@ public class GlobalFeatureInterceptor : AbpInterceptor, ITransientDependency
if (!GlobalFeatureHelper.IsGlobalFeatureEnabled(invocation.TargetObject.GetType(), out var attribute)) if (!GlobalFeatureHelper.IsGlobalFeatureEnabled(invocation.TargetObject.GetType(), out var attribute))
{ {
throw new AbpGlobalFeatureNotEnabledException(code: AbpGlobalFeatureErrorCodes.GlobalFeatureIsNotEnabled) throw new AbpGlobalFeatureNotEnabledException(code: AbpGlobalFeatureErrorCodes.GlobalFeatureIsNotEnabled)
.WithData("ServiceName", invocation.TargetObject.GetType().FullName) .WithData("ServiceName", invocation.TargetObject.GetType().FullName!)
.WithData("GlobalFeatureName", attribute.Name); .WithData("GlobalFeatureName", attribute!.Name!);
} }
await invocation.ProceedAsync(); await invocation.ProceedAsync();

6
framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeaturesSimpleStateCheckerSerializerContributor.cs

@ -11,7 +11,7 @@ public class GlobalFeaturesSimpleStateCheckerSerializerContributor :
{ {
public const string CheckerShortName = "G"; public const string CheckerShortName = "G";
public string SerializeToJson<TState>(ISimpleStateChecker<TState> checker) public string? SerializeToJson<TState>(ISimpleStateChecker<TState> checker)
where TState : IHasSimpleStateCheckers<TState> where TState : IHasSimpleStateCheckers<TState>
{ {
if (checker is not RequireGlobalFeaturesSimpleStateChecker<TState> globalFeaturesSimpleStateChecker) if (checker is not RequireGlobalFeaturesSimpleStateChecker<TState> globalFeaturesSimpleStateChecker)
@ -34,7 +34,7 @@ public class GlobalFeaturesSimpleStateCheckerSerializerContributor :
return jsonObject.ToJsonString(); return jsonObject.ToJsonString();
} }
public ISimpleStateChecker<TState> Deserialize<TState>(JsonObject jsonObject, TState state) public ISimpleStateChecker<TState>? Deserialize<TState>(JsonObject jsonObject, TState state)
where TState : IHasSimpleStateCheckers<TState> where TState : IHasSimpleStateCheckers<TState>
{ {
if (jsonObject["T"]?.ToString() != CheckerShortName) if (jsonObject["T"]?.ToString() != CheckerShortName)
@ -50,7 +50,7 @@ public class GlobalFeaturesSimpleStateCheckerSerializerContributor :
return new RequireGlobalFeaturesSimpleStateChecker<TState>( return new RequireGlobalFeaturesSimpleStateChecker<TState>(
(bool?)jsonObject["A"] ?? false, (bool?)jsonObject["A"] ?? false,
nameArray.Select(x => x.ToString()).ToArray() nameArray.Select(x => x!.ToString()).ToArray()
); );
} }
} }

6
framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/RequiresGlobalFeatureAttribute.cs

@ -6,9 +6,9 @@ namespace Volo.Abp.GlobalFeatures;
[AttributeUsage(AttributeTargets.Class)] [AttributeUsage(AttributeTargets.Class)]
public class RequiresGlobalFeatureAttribute : Attribute public class RequiresGlobalFeatureAttribute : Attribute
{ {
public Type Type { get; } public Type? Type { get; }
public string Name { get; } public string? Name { get; }
public RequiresGlobalFeatureAttribute([NotNull] Type type) public RequiresGlobalFeatureAttribute([NotNull] Type type)
{ {
@ -22,6 +22,6 @@ public class RequiresGlobalFeatureAttribute : Attribute
public virtual string GetFeatureName() public virtual string GetFeatureName()
{ {
return Name ?? GlobalFeatureNameAttribute.GetName(Type); return Name ?? GlobalFeatureNameAttribute.GetName(Type!);
} }
} }

Loading…
Cancel
Save