From aeadf8bb09196b1391e7b0b5f4f3b35178be6988 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 13 Jul 2023 14:02:56 +0800 Subject: [PATCH] Enable nullable annotations for Volo.Abp.GlobalFeatures --- .../Volo.Abp.GlobalFeatures/Volo.Abp.GlobalFeatures.csproj | 2 ++ .../GlobalFeatures/AbpGlobalFeatureNotEnabledException.cs | 4 ++-- .../Volo/Abp/GlobalFeatures/GlobalFeatureHelper.cs | 2 +- .../Volo/Abp/GlobalFeatures/GlobalFeatureInterceptor.cs | 4 ++-- ...GlobalFeaturesSimpleStateCheckerSerializerContributor.cs | 6 +++--- .../Abp/GlobalFeatures/RequiresGlobalFeatureAttribute.cs | 6 +++--- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/framework/src/Volo.Abp.GlobalFeatures/Volo.Abp.GlobalFeatures.csproj b/framework/src/Volo.Abp.GlobalFeatures/Volo.Abp.GlobalFeatures.csproj index 7862b829c7..5f6200d037 100644 --- a/framework/src/Volo.Abp.GlobalFeatures/Volo.Abp.GlobalFeatures.csproj +++ b/framework/src/Volo.Abp.GlobalFeatures/Volo.Abp.GlobalFeatures.csproj @@ -5,6 +5,8 @@ netstandard2.0;netstandard2.1;net7.0 + enable + Nullable Volo.Abp.GlobalFeatures Volo.Abp.GlobalFeatures $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; diff --git a/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/AbpGlobalFeatureNotEnabledException.cs b/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/AbpGlobalFeatureNotEnabledException.cs index d089602ba8..8a5c01f635 100644 --- a/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/AbpGlobalFeatureNotEnabledException.cs +++ b/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/AbpGlobalFeatureNotEnabledException.cs @@ -6,9 +6,9 @@ namespace Volo.Abp.GlobalFeatures; [Serializable] 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) { Code = code; diff --git a/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureHelper.cs b/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureHelper.cs index 1ec847fba2..3e7b56a030 100644 --- a/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureHelper.cs +++ b/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureHelper.cs @@ -5,7 +5,7 @@ namespace Volo.Abp.GlobalFeatures; 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(type); return attribute == null || GlobalFeatureManager.Instance.IsEnabled(attribute.GetFeatureName()); diff --git a/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureInterceptor.cs b/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureInterceptor.cs index 275d2299ea..f2a5d65b2c 100644 --- a/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureInterceptor.cs +++ b/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)) { throw new AbpGlobalFeatureNotEnabledException(code: AbpGlobalFeatureErrorCodes.GlobalFeatureIsNotEnabled) - .WithData("ServiceName", invocation.TargetObject.GetType().FullName) - .WithData("GlobalFeatureName", attribute.Name); + .WithData("ServiceName", invocation.TargetObject.GetType().FullName!) + .WithData("GlobalFeatureName", attribute!.Name!); } await invocation.ProceedAsync(); diff --git a/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeaturesSimpleStateCheckerSerializerContributor.cs b/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeaturesSimpleStateCheckerSerializerContributor.cs index d4abc25403..fe8530435b 100644 --- a/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeaturesSimpleStateCheckerSerializerContributor.cs +++ b/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeaturesSimpleStateCheckerSerializerContributor.cs @@ -11,7 +11,7 @@ public class GlobalFeaturesSimpleStateCheckerSerializerContributor : { public const string CheckerShortName = "G"; - public string SerializeToJson(ISimpleStateChecker checker) + public string? SerializeToJson(ISimpleStateChecker checker) where TState : IHasSimpleStateCheckers { if (checker is not RequireGlobalFeaturesSimpleStateChecker globalFeaturesSimpleStateChecker) @@ -34,7 +34,7 @@ public class GlobalFeaturesSimpleStateCheckerSerializerContributor : return jsonObject.ToJsonString(); } - public ISimpleStateChecker Deserialize(JsonObject jsonObject, TState state) + public ISimpleStateChecker? Deserialize(JsonObject jsonObject, TState state) where TState : IHasSimpleStateCheckers { if (jsonObject["T"]?.ToString() != CheckerShortName) @@ -50,7 +50,7 @@ public class GlobalFeaturesSimpleStateCheckerSerializerContributor : return new RequireGlobalFeaturesSimpleStateChecker( (bool?)jsonObject["A"] ?? false, - nameArray.Select(x => x.ToString()).ToArray() + nameArray.Select(x => x!.ToString()).ToArray() ); } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/RequiresGlobalFeatureAttribute.cs b/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/RequiresGlobalFeatureAttribute.cs index 788d0642aa..f9fc5d00ba 100644 --- a/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/RequiresGlobalFeatureAttribute.cs +++ b/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/RequiresGlobalFeatureAttribute.cs @@ -6,9 +6,9 @@ namespace Volo.Abp.GlobalFeatures; [AttributeUsage(AttributeTargets.Class)] 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) { @@ -22,6 +22,6 @@ public class RequiresGlobalFeatureAttribute : Attribute public virtual string GetFeatureName() { - return Name ?? GlobalFeatureNameAttribute.GetName(Type); + return Name ?? GlobalFeatureNameAttribute.GetName(Type!); } }