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>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.GlobalFeatures</AssemblyName>
<PackageId>Volo.Abp.GlobalFeatures</PackageId>
<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]
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;

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 bool IsGlobalFeatureEnabled(Type type, out RequiresGlobalFeatureAttribute attribute)
public static bool IsGlobalFeatureEnabled(Type type, out RequiresGlobalFeatureAttribute? attribute)
{
attribute = ReflectionHelper.GetSingleAttributeOrDefault<RequiresGlobalFeatureAttribute>(type);
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))
{
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();

6
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<TState>(ISimpleStateChecker<TState> checker)
public string? SerializeToJson<TState>(ISimpleStateChecker<TState> checker)
where TState : IHasSimpleStateCheckers<TState>
{
if (checker is not RequireGlobalFeaturesSimpleStateChecker<TState> globalFeaturesSimpleStateChecker)
@ -34,7 +34,7 @@ public class GlobalFeaturesSimpleStateCheckerSerializerContributor :
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>
{
if (jsonObject["T"]?.ToString() != CheckerShortName)
@ -50,7 +50,7 @@ public class GlobalFeaturesSimpleStateCheckerSerializerContributor :
return new RequireGlobalFeaturesSimpleStateChecker<TState>(
(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)]
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!);
}
}

Loading…
Cancel
Save