Browse Source

Enable nullable annotations for Volo.Abp.Core

pull/16693/head
liangshiwei 3 years ago
parent
commit
4e2e2d4bec
  1. 12
      framework/src/Volo.Abp.Core/Microsoft/Extensions/Configuration/AbpConfigurationBuilderOptions.cs
  2. 6
      framework/src/Volo.Abp.Core/Microsoft/Extensions/Configuration/ConfigurationHelper.cs
  3. 11
      framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionApplicationExtensions.cs
  4. 26
      framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs
  5. 2
      framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionConfigurationExtensions.cs
  6. 2
      framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionObjectAccessorExtensions.cs
  7. 17
      framework/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs
  8. 2
      framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs
  9. 12
      framework/src/Volo.Abp.Core/System/AbpStringExtensions.cs
  10. 4
      framework/src/Volo.Abp.Core/System/AbpTypeExtensions.cs
  11. 2
      framework/src/Volo.Abp.Core/System/Collections/Generic/AbpCollectionExtensions.cs
  12. 20
      framework/src/Volo.Abp.Core/System/Collections/Generic/AbpDictionaryExtensions.cs
  13. 4
      framework/src/Volo.Abp.Core/System/Collections/Generic/AbpListExtensions.cs
  14. 24
      framework/src/Volo.Abp.Core/System/Linq/PredicateOperator.cs
  15. 2
      framework/src/Volo.Abp.Core/System/Reflection/AbpAssemblyExtensions.cs
  16. 6
      framework/src/Volo.Abp.Core/System/Reflection/AbpMemberInfoExtensions.cs
  17. 1
      framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj
  18. 16
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs
  19. 6
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationCreationOptions.cs
  20. 16
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationFactory.cs
  21. 3
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationWithExternalServiceProvider.cs
  22. 9
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationWithInternalServiceProvider.cs
  23. 2
      framework/src/Volo.Abp.Core/Volo/Abp/AbpHostEnvironment.cs
  24. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleContext.cs
  25. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleDefinition.cs
  26. 12
      framework/src/Volo.Abp.Core/Volo/Abp/BusinessException.cs
  27. 6
      framework/src/Volo.Abp.Core/Volo/Abp/Check.cs
  28. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Content/IRemoteStreamContent.cs
  29. 4
      framework/src/Volo.Abp.Core/Volo/Abp/Content/RemoteStreamContent.cs
  30. 6
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/AbpLazyServiceProvider.cs
  31. 16
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/CachedServiceProviderBase.cs
  32. 8
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ConventionalRegistrarBase.cs
  33. 4
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/IAbpLazyServiceProvider.cs
  34. 3
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/IObjectAccessor.cs
  35. 4
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ObjectAccessor.cs
  36. 4
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/RootServiceProvider.cs
  37. 8
      framework/src/Volo.Abp.Core/Volo/Abp/DisposeAction.cs
  38. 13
      framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/ProxyHelper.cs
  39. 2
      framework/src/Volo.Abp.Core/Volo/Abp/ExceptionHandling/IHasErrorCode.cs
  40. 2
      framework/src/Volo.Abp.Core/Volo/Abp/ExceptionHandling/IHasErrorDetails.cs
  41. 2
      framework/src/Volo.Abp.Core/Volo/Abp/IAbpHostEnvironment.cs
  42. 3
      framework/src/Volo.Abp.Core/Volo/Abp/IApplicationInfoAccessor.cs
  43. 9
      framework/src/Volo.Abp.Core/Volo/Abp/IO/FileHelper.cs
  44. 4
      framework/src/Volo.Abp.Core/Volo/Abp/Localization/CultureHelper.cs
  45. 6
      framework/src/Volo.Abp.Core/Volo/Abp/Logging/AbpInitLogEntry.cs
  46. 6
      framework/src/Volo.Abp.Core/Volo/Abp/Logging/DefaultInitLogger.cs
  47. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Modularity/AbpModule.cs
  48. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Modularity/DependsOnAttribute.cs
  49. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Modularity/ModuleLoader.cs
  50. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Modularity/PlugIns/FilePlugInSource.cs
  51. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Modularity/PlugIns/FolderPlugInSource.cs
  52. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Modularity/PlugIns/TypePlugInSource.cs
  53. 6
      framework/src/Volo.Abp.Core/Volo/Abp/Modularity/ServiceConfigurationContext.cs
  54. 4
      framework/src/Volo.Abp.Core/Volo/Abp/NameValue.cs
  55. 10
      framework/src/Volo.Abp.Core/Volo/Abp/ObjectHelper.cs
  56. 4
      framework/src/Volo.Abp.Core/Volo/Abp/Options/AbpOptionsFactory.cs
  57. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Reflection/AssemblyHelper.cs
  58. 18
      framework/src/Volo.Abp.Core/Volo/Abp/Reflection/ReflectionHelper.cs
  59. 28
      framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs
  60. 2
      framework/src/Volo.Abp.Core/Volo/Abp/RemoteServiceAttribute.cs
  61. 4
      framework/src/Volo.Abp.Core/Volo/Abp/SimpleStateChecking/ISimpleStateCheckerSerializer.cs
  62. 6
      framework/src/Volo.Abp.Core/Volo/Abp/SimpleStateChecking/ISimpleStateCheckerSerializerContributor.cs
  63. 6
      framework/src/Volo.Abp.Core/Volo/Abp/SimpleStateChecking/SimpleStateCheckerSerializer.cs
  64. 6
      framework/src/Volo.Abp.Core/Volo/Abp/SimpleStateChecking/SimpleStateCheckerSerializerExtensions.cs
  65. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Text/Formatting/FormattedStringValueExtracter.cs
  66. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Text/StringHelper.cs
  67. 40
      framework/src/Volo.Abp.Core/Volo/Abp/Threading/InternalAsyncHelper.cs
  68. 6
      framework/src/Volo.Abp.Core/Volo/Abp/UserFriendlyException.cs
  69. 6
      framework/src/Volo.Abp.Core/Volo/Abp/Validation/DynamicMaxLengthAttribute.cs
  70. 12
      framework/src/Volo.Abp.Core/Volo/Abp/Validation/DynamicRangeAttribute.cs
  71. 10
      framework/src/Volo.Abp.Core/Volo/Abp/Validation/DynamicStringLengthAttribute.cs

12
framework/src/Volo.Abp.Core/Microsoft/Extensions/Configuration/AbpConfigurationBuilderOptions.cs

@ -8,13 +8,13 @@ public class AbpConfigurationBuilderOptions
/// Used to set assembly which is used to get the user secret id for the application. /// Used to set assembly which is used to get the user secret id for the application.
/// Use this or <see cref="UserSecretsId"/> (higher priority) /// Use this or <see cref="UserSecretsId"/> (higher priority)
/// </summary> /// </summary>
public Assembly UserSecretsAssembly { get; set; } public Assembly? UserSecretsAssembly { get; set; }
/// <summary> /// <summary>
/// Used to set user secret id for the application. /// Used to set user secret id for the application.
/// Use this (higher priority) or <see cref="UserSecretsAssembly"/> /// Use this (higher priority) or <see cref="UserSecretsAssembly"/>
/// </summary> /// </summary>
public string UserSecretsId { get; set; } public string? UserSecretsId { get; set; }
/// <summary> /// <summary>
/// Default value: "appsettings". /// Default value: "appsettings".
@ -34,20 +34,20 @@ public class AbpConfigurationBuilderOptions
/// <summary> /// <summary>
/// Environment name. Generally used "Development", "Staging" or "Production". /// Environment name. Generally used "Development", "Staging" or "Production".
/// </summary> /// </summary>
public string EnvironmentName { get; set; } public string? EnvironmentName { get; set; }
/// <summary> /// <summary>
/// Base path to read the configuration file indicated by <see cref="FileName"/>. /// Base path to read the configuration file indicated by <see cref="FileName"/>.
/// </summary> /// </summary>
public string BasePath { get; set; } public string? BasePath { get; set; }
/// <summary> /// <summary>
/// Prefix for the environment variables. /// Prefix for the environment variables.
/// </summary> /// </summary>
public string EnvironmentVariablesPrefix { get; set; } public string? EnvironmentVariablesPrefix { get; set; }
/// <summary> /// <summary>
/// Command line arguments. /// Command line arguments.
/// </summary> /// </summary>
public string[] CommandLineArgs { get; set; } public string[]? CommandLineArgs { get; set; }
} }

6
framework/src/Volo.Abp.Core/Microsoft/Extensions/Configuration/ConfigurationHelper.cs

@ -6,8 +6,8 @@ namespace Microsoft.Extensions.Configuration;
public static class ConfigurationHelper public static class ConfigurationHelper
{ {
public static IConfigurationRoot BuildConfiguration( public static IConfigurationRoot BuildConfiguration(
AbpConfigurationBuilderOptions options = null, AbpConfigurationBuilderOptions? options = null,
Action<IConfigurationBuilder> builderAction = null) Action<IConfigurationBuilder>? builderAction = null)
{ {
options ??= new AbpConfigurationBuilderOptions(); options ??= new AbpConfigurationBuilderOptions();
@ -17,7 +17,7 @@ public static class ConfigurationHelper
} }
var builder = new ConfigurationBuilder() var builder = new ConfigurationBuilder()
.SetBasePath(options.BasePath) .SetBasePath(options.BasePath!)
.AddJsonFile(options.FileName + ".json", optional: options.Optional, reloadOnChange: options.ReloadOnChange); .AddJsonFile(options.FileName + ".json", optional: options.Optional, reloadOnChange: options.ReloadOnChange);
if (!options.EnvironmentName.IsNullOrEmpty()) if (!options.EnvironmentName.IsNullOrEmpty())

11
framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionApplicationExtensions.cs

@ -10,7 +10,7 @@ public static class ServiceCollectionApplicationExtensions
{ {
public static IAbpApplicationWithExternalServiceProvider AddApplication<TStartupModule>( public static IAbpApplicationWithExternalServiceProvider AddApplication<TStartupModule>(
[NotNull] this IServiceCollection services, [NotNull] this IServiceCollection services,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction = null) Action<AbpApplicationCreationOptions>? optionsAction = null)
where TStartupModule : IAbpModule where TStartupModule : IAbpModule
{ {
return AbpApplicationFactory.Create<TStartupModule>(services, optionsAction); return AbpApplicationFactory.Create<TStartupModule>(services, optionsAction);
@ -19,14 +19,14 @@ public static class ServiceCollectionApplicationExtensions
public static IAbpApplicationWithExternalServiceProvider AddApplication( public static IAbpApplicationWithExternalServiceProvider AddApplication(
[NotNull] this IServiceCollection services, [NotNull] this IServiceCollection services,
[NotNull] Type startupModuleType, [NotNull] Type startupModuleType,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction = null) Action<AbpApplicationCreationOptions>? optionsAction = null)
{ {
return AbpApplicationFactory.Create(startupModuleType, services, optionsAction); return AbpApplicationFactory.Create(startupModuleType, services, optionsAction);
} }
public async static Task<IAbpApplicationWithExternalServiceProvider> AddApplicationAsync<TStartupModule>( public async static Task<IAbpApplicationWithExternalServiceProvider> AddApplicationAsync<TStartupModule>(
[NotNull] this IServiceCollection services, [NotNull] this IServiceCollection services,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction = null) Action<AbpApplicationCreationOptions>? optionsAction = null)
where TStartupModule : IAbpModule where TStartupModule : IAbpModule
{ {
return await AbpApplicationFactory.CreateAsync<TStartupModule>(services, optionsAction); return await AbpApplicationFactory.CreateAsync<TStartupModule>(services, optionsAction);
@ -35,13 +35,12 @@ public static class ServiceCollectionApplicationExtensions
public async static Task<IAbpApplicationWithExternalServiceProvider> AddApplicationAsync( public async static Task<IAbpApplicationWithExternalServiceProvider> AddApplicationAsync(
[NotNull] this IServiceCollection services, [NotNull] this IServiceCollection services,
[NotNull] Type startupModuleType, [NotNull] Type startupModuleType,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction = null) Action<AbpApplicationCreationOptions>? optionsAction = null)
{ {
return await AbpApplicationFactory.CreateAsync(startupModuleType, services, optionsAction); return await AbpApplicationFactory.CreateAsync(startupModuleType, services, optionsAction);
} }
[CanBeNull] public static string? GetApplicationName(this IServiceCollection services)
public static string GetApplicationName(this IServiceCollection services)
{ {
return services.GetSingletonInstance<IApplicationInfoAccessor>().ApplicationName; return services.GetSingletonInstance<IApplicationInfoAccessor>().ApplicationName;
} }

26
framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs

@ -24,9 +24,9 @@ public static class ServiceCollectionCommonExtensions
return services.GetSingletonInstance<ITypeFinder>(); return services.GetSingletonInstance<ITypeFinder>();
} }
public static T GetSingletonInstanceOrNull<T>(this IServiceCollection services) public static T? GetSingletonInstanceOrNull<T>(this IServiceCollection services)
{ {
return (T)services return (T?)services
.FirstOrDefault(d => d.ServiceType == typeof(T)) .FirstOrDefault(d => d.ServiceType == typeof(T))
?.ImplementationInstance; ?.ImplementationInstance;
} }
@ -65,13 +65,13 @@ public static class ServiceCollectionCommonExtensions
.GetMethods() .GetMethods()
.Single(m => m.Name == nameof(BuildServiceProviderFromFactory) && m.IsGenericMethod) .Single(m => m.Name == nameof(BuildServiceProviderFromFactory) && m.IsGenericMethod)
.MakeGenericMethod(containerBuilderType) .MakeGenericMethod(containerBuilderType)
.Invoke(null, new object[] { services, null }); .Invoke(null, new object?[] { services, null })!;
} }
return services.BuildServiceProvider(); return services.BuildServiceProvider();
} }
public static IServiceProvider BuildServiceProviderFromFactory<TContainerBuilder>([NotNull] this IServiceCollection services, Action<TContainerBuilder> builderAction = null) public static IServiceProvider BuildServiceProviderFromFactory<TContainerBuilder>([NotNull] this IServiceCollection services, Action<TContainerBuilder>? builderAction = null) where TContainerBuilder : notnull
{ {
Check.NotNull(services, nameof(services)); Check.NotNull(services, nameof(services));
@ -90,7 +90,7 @@ public static class ServiceCollectionCommonExtensions
/// Resolves a dependency using given <see cref="IServiceCollection"/>. /// Resolves a dependency using given <see cref="IServiceCollection"/>.
/// This method should be used only after dependency injection registration phase completed. /// This method should be used only after dependency injection registration phase completed.
/// </summary> /// </summary>
internal static T GetService<T>(this IServiceCollection services) internal static T? GetService<T>(this IServiceCollection services)
{ {
return services return services
.GetSingletonInstance<IAbpApplication>() .GetSingletonInstance<IAbpApplication>()
@ -102,7 +102,7 @@ public static class ServiceCollectionCommonExtensions
/// Resolves a dependency using given <see cref="IServiceCollection"/>. /// Resolves a dependency using given <see cref="IServiceCollection"/>.
/// This method should be used only after dependency injection registration phase completed. /// This method should be used only after dependency injection registration phase completed.
/// </summary> /// </summary>
internal static object GetService(this IServiceCollection services, Type type) internal static object? GetService(this IServiceCollection services, Type type)
{ {
return services return services
.GetSingletonInstance<IAbpApplication>() .GetSingletonInstance<IAbpApplication>()
@ -115,7 +115,7 @@ public static class ServiceCollectionCommonExtensions
/// Throws exception if service is not registered. /// Throws exception if service is not registered.
/// This method should be used only after dependency injection registration phase completed. /// This method should be used only after dependency injection registration phase completed.
/// </summary> /// </summary>
public static T GetRequiredService<T>(this IServiceCollection services) public static T GetRequiredService<T>(this IServiceCollection services) where T : notnull
{ {
return services return services
.GetSingletonInstance<IAbpApplication>() .GetSingletonInstance<IAbpApplication>()
@ -140,25 +140,25 @@ public static class ServiceCollectionCommonExtensions
/// Returns a <see cref="Lazy{T}"/> to resolve a service from given <see cref="IServiceCollection"/> /// Returns a <see cref="Lazy{T}"/> to resolve a service from given <see cref="IServiceCollection"/>
/// once dependency injection registration phase completed. /// once dependency injection registration phase completed.
/// </summary> /// </summary>
public static Lazy<T> GetServiceLazy<T>(this IServiceCollection services) public static Lazy<T?> GetServiceLazy<T>(this IServiceCollection services)
{ {
return new Lazy<T>(services.GetService<T>, true); return new Lazy<T?>(services.GetService<T>, true);
} }
/// <summary> /// <summary>
/// Returns a <see cref="Lazy{T}"/> to resolve a service from given <see cref="IServiceCollection"/> /// Returns a <see cref="Lazy{T}"/> to resolve a service from given <see cref="IServiceCollection"/>
/// once dependency injection registration phase completed. /// once dependency injection registration phase completed.
/// </summary> /// </summary>
public static Lazy<object> GetServiceLazy(this IServiceCollection services, Type type) public static Lazy<object?> GetServiceLazy(this IServiceCollection services, Type type)
{ {
return new Lazy<object>(() => services.GetService(type), true); return new Lazy<object?>(() => services.GetService(type), true);
} }
/// <summary> /// <summary>
/// Returns a <see cref="Lazy{T}"/> to resolve a service from given <see cref="IServiceCollection"/> /// Returns a <see cref="Lazy{T}"/> to resolve a service from given <see cref="IServiceCollection"/>
/// once dependency injection registration phase completed. /// once dependency injection registration phase completed.
/// </summary> /// </summary>
public static Lazy<T> GetRequiredServiceLazy<T>(this IServiceCollection services) public static Lazy<T> GetRequiredServiceLazy<T>(this IServiceCollection services) where T : notnull
{ {
return new Lazy<T>(services.GetRequiredService<T>, true); return new Lazy<T>(services.GetRequiredService<T>, true);
} }
@ -172,7 +172,7 @@ public static class ServiceCollectionCommonExtensions
return new Lazy<object>(() => services.GetRequiredService(type), true); return new Lazy<object>(() => services.GetRequiredService(type), true);
} }
public static IServiceProvider GetServiceProviderOrNull(this IServiceCollection services) public static IServiceProvider? GetServiceProviderOrNull(this IServiceCollection services)
{ {
return services.GetObjectOrNull<IServiceProvider>(); return services.GetObjectOrNull<IServiceProvider>();
} }

2
framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionConfigurationExtensions.cs

@ -21,7 +21,7 @@ public static class ServiceCollectionConfigurationExtensions
} }
[CanBeNull] [CanBeNull]
public static IConfiguration GetConfigurationOrNull(this IServiceCollection services) public static IConfiguration? GetConfigurationOrNull(this IServiceCollection services)
{ {
var hostBuilderContext = services.GetSingletonInstanceOrNull<HostBuilderContext>(); var hostBuilderContext = services.GetSingletonInstanceOrNull<HostBuilderContext>();
if (hostBuilderContext?.Configuration != null) if (hostBuilderContext?.Configuration != null)

2
framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionObjectAccessorExtensions.cs

@ -40,7 +40,7 @@ public static class ServiceCollectionObjectAccessorExtensions
return accessor; return accessor;
} }
public static T GetObjectOrNull<T>(this IServiceCollection services) public static T? GetObjectOrNull<T>(this IServiceCollection services)
where T : class where T : class
{ {
return services.GetSingletonInstanceOrNull<IObjectAccessor<T>>()?.Value; return services.GetSingletonInstanceOrNull<IObjectAccessor<T>>()?.Value;

17
framework/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs

@ -83,7 +83,7 @@ public static class AbpLoggerExtensions
private static void LogData(ILogger logger, Exception exception, LogLevel logLevel) private static void LogData(ILogger logger, Exception exception, LogLevel logLevel)
{ {
if (exception.Data == null || exception.Data.Count <= 0) if (exception.Data.Count <= 0)
{ {
return; return;
} }
@ -102,23 +102,22 @@ public static class AbpLoggerExtensions
{ {
var loggingExceptions = new List<IExceptionWithSelfLogging>(); var loggingExceptions = new List<IExceptionWithSelfLogging>();
if (exception is IExceptionWithSelfLogging) if (exception is IExceptionWithSelfLogging logging)
{ {
loggingExceptions.Add(exception as IExceptionWithSelfLogging); loggingExceptions.Add(logging);
} }
else if (exception is AggregateException && exception.InnerException != null) else if (exception is AggregateException aggException && aggException.InnerException != null)
{ {
var aggException = exception as AggregateException; if (aggException.InnerException is IExceptionWithSelfLogging selfLogging)
if (aggException.InnerException is IExceptionWithSelfLogging)
{ {
loggingExceptions.Add(aggException.InnerException as IExceptionWithSelfLogging); loggingExceptions.Add(selfLogging);
} }
foreach (var innerException in aggException.InnerExceptions) foreach (var innerException in aggException.InnerExceptions)
{ {
if (innerException is IExceptionWithSelfLogging) if (innerException is IExceptionWithSelfLogging withSelfLogging)
{ {
loggingExceptions.AddIfNotContains(innerException as IExceptionWithSelfLogging); loggingExceptions.AddIfNotContains(withSelfLogging);
} }
} }
} }

2
framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs

@ -36,7 +36,7 @@ public static class AbpObjectExtensions
{ {
if (typeof(T) == typeof(Guid)) if (typeof(T) == typeof(Guid))
{ {
return (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(obj.ToString()); return (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(obj.ToString()!)!;
} }
return (T)Convert.ChangeType(obj, typeof(T), CultureInfo.InvariantCulture); return (T)Convert.ChangeType(obj, typeof(T), CultureInfo.InvariantCulture);

12
framework/src/Volo.Abp.Core/System/AbpStringExtensions.cs

@ -47,7 +47,7 @@ public static class AbpStringExtensions
/// Indicates whether this string is null or an System.String.Empty string. /// Indicates whether this string is null or an System.String.Empty string.
/// </summary> /// </summary>
[ContractAnnotation("str:null => true")] [ContractAnnotation("str:null => true")]
public static bool IsNullOrEmpty(this string str) public static bool IsNullOrEmpty(this string? str)
{ {
return string.IsNullOrEmpty(str); return string.IsNullOrEmpty(str);
} }
@ -56,7 +56,7 @@ public static class AbpStringExtensions
/// indicates whether this string is null, empty, or consists only of white-space characters. /// indicates whether this string is null, empty, or consists only of white-space characters.
/// </summary> /// </summary>
[ContractAnnotation("str:null => true")] [ContractAnnotation("str:null => true")]
public static bool IsNullOrWhiteSpace(this string str) public static bool IsNullOrWhiteSpace(this string? str)
{ {
return string.IsNullOrWhiteSpace(str); return string.IsNullOrWhiteSpace(str);
} }
@ -482,7 +482,7 @@ public static class AbpStringExtensions
/// Gets a substring of a string from beginning of the string if it exceeds maximum length. /// Gets a substring of a string from beginning of the string if it exceeds maximum length.
/// </summary> /// </summary>
[ContractAnnotation("null <= str:null")] [ContractAnnotation("null <= str:null")]
public static string Truncate(this string str, int maxLength) public static string? Truncate(this string? str, int maxLength)
{ {
if (str == null) if (str == null)
{ {
@ -501,7 +501,7 @@ public static class AbpStringExtensions
/// Gets a substring of a string from Ending of the string if it exceeds maximum length. /// Gets a substring of a string from Ending of the string if it exceeds maximum length.
/// </summary> /// </summary>
[ContractAnnotation("null <= str:null")] [ContractAnnotation("null <= str:null")]
public static string TruncateFromBeginning(this string str, int maxLength) public static string? TruncateFromBeginning(this string? str, int maxLength)
{ {
if (str == null) if (str == null)
{ {
@ -522,7 +522,7 @@ public static class AbpStringExtensions
/// Returning string can not be longer than maxLength. /// Returning string can not be longer than maxLength.
/// </summary> /// </summary>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
public static string TruncateWithPostfix(this string str, int maxLength) public static string? TruncateWithPostfix(this string? str, int maxLength)
{ {
return TruncateWithPostfix(str, maxLength, "..."); return TruncateWithPostfix(str, maxLength, "...");
} }
@ -534,7 +534,7 @@ public static class AbpStringExtensions
/// </summary> /// </summary>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
[ContractAnnotation("null <= str:null")] [ContractAnnotation("null <= str:null")]
public static string TruncateWithPostfix(this string str, int maxLength, string postfix) public static string? TruncateWithPostfix(this string? str, int maxLength, string postfix)
{ {
if (str == null) if (str == null)
{ {

4
framework/src/Volo.Abp.Core/System/AbpTypeExtensions.cs

@ -72,9 +72,9 @@ public static class AbpTypeExtensions
private static void AddTypeAndBaseTypesRecursively( private static void AddTypeAndBaseTypesRecursively(
[NotNull] List<Type> types, [NotNull] List<Type> types,
[CanBeNull] Type type, Type? type,
bool includeObject, bool includeObject,
[CanBeNull] Type stoppingType = null) Type? stoppingType = null)
{ {
if (type == null || type == stoppingType) if (type == null || type == stoppingType)
{ {

2
framework/src/Volo.Abp.Core/System/Collections/Generic/AbpCollectionExtensions.cs

@ -13,7 +13,7 @@ public static class AbpCollectionExtensions
/// Checks whatever given collection object is null or has no item. /// Checks whatever given collection object is null or has no item.
/// </summary> /// </summary>
[ContractAnnotation("source:null => true")] [ContractAnnotation("source:null => true")]
public static bool IsNullOrEmpty<T>([CanBeNull] this ICollection<T> source) public static bool IsNullOrEmpty<T>(this ICollection<T>? source)
{ {
return source == null || source.Count <= 0; return source == null || source.Count <= 0;
} }

20
framework/src/Volo.Abp.Core/System/Collections/Generic/AbpDictionaryExtensions.cs

@ -16,9 +16,9 @@ public static class AbpDictionaryExtensions
/// <param name="key">Key</param> /// <param name="key">Key</param>
/// <param name="value">Value of the key (or default value if key not exists)</param> /// <param name="value">Value of the key (or default value if key not exists)</param>
/// <returns>True if key does exists in the dictionary</returns> /// <returns>True if key does exists in the dictionary</returns>
internal static bool TryGetValue<T>(this IDictionary<string, object> dictionary, string key, out T value) internal static bool TryGetValue<T>(this IDictionary<string, object> dictionary, string key, out T? value)
{ {
object valueObj; object? valueObj;
if (dictionary.TryGetValue(key, out valueObj) && valueObj is T) if (dictionary.TryGetValue(key, out valueObj) && valueObj is T)
{ {
value = (T)valueObj; value = (T)valueObj;
@ -37,9 +37,9 @@ public static class AbpDictionaryExtensions
/// <typeparam name="TKey">Type of the key</typeparam> /// <typeparam name="TKey">Type of the key</typeparam>
/// <typeparam name="TValue">Type of the value</typeparam> /// <typeparam name="TValue">Type of the value</typeparam>
/// <returns>Value if found, default if can not found.</returns> /// <returns>Value if found, default if can not found.</returns>
public static TValue GetOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key) public static TValue? GetOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull
{ {
TValue obj; TValue? obj;
return dictionary.TryGetValue(key, out obj) ? obj : default; return dictionary.TryGetValue(key, out obj) ? obj : default;
} }
@ -51,7 +51,7 @@ public static class AbpDictionaryExtensions
/// <typeparam name="TKey">Type of the key</typeparam> /// <typeparam name="TKey">Type of the key</typeparam>
/// <typeparam name="TValue">Type of the value</typeparam> /// <typeparam name="TValue">Type of the value</typeparam>
/// <returns>Value if found, default if can not found.</returns> /// <returns>Value if found, default if can not found.</returns>
public static TValue GetOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key) public static TValue? GetOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
{ {
return dictionary.TryGetValue(key, out var obj) ? obj : default; return dictionary.TryGetValue(key, out var obj) ? obj : default;
} }
@ -64,7 +64,7 @@ public static class AbpDictionaryExtensions
/// <typeparam name="TKey">Type of the key</typeparam> /// <typeparam name="TKey">Type of the key</typeparam>
/// <typeparam name="TValue">Type of the value</typeparam> /// <typeparam name="TValue">Type of the value</typeparam>
/// <returns>Value if found, default if can not found.</returns> /// <returns>Value if found, default if can not found.</returns>
public static TValue GetOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key) public static TValue? GetOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)
{ {
return dictionary.TryGetValue(key, out var obj) ? obj : default; return dictionary.TryGetValue(key, out var obj) ? obj : default;
} }
@ -77,7 +77,7 @@ public static class AbpDictionaryExtensions
/// <typeparam name="TKey">Type of the key</typeparam> /// <typeparam name="TKey">Type of the key</typeparam>
/// <typeparam name="TValue">Type of the value</typeparam> /// <typeparam name="TValue">Type of the value</typeparam>
/// <returns>Value if found, default if can not found.</returns> /// <returns>Value if found, default if can not found.</returns>
public static TValue GetOrDefault<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary, TKey key) public static TValue? GetOrDefault<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull
{ {
return dictionary.TryGetValue(key, out var obj) ? obj : default; return dictionary.TryGetValue(key, out var obj) ? obj : default;
} }
@ -93,7 +93,7 @@ public static class AbpDictionaryExtensions
/// <returns>Value if found, default if can not found.</returns> /// <returns>Value if found, default if can not found.</returns>
public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> factory) public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> factory)
{ {
TValue obj; TValue? obj;
if (dictionary.TryGetValue(key, out obj)) if (dictionary.TryGetValue(key, out obj))
{ {
return obj; return obj;
@ -125,7 +125,7 @@ public static class AbpDictionaryExtensions
/// <typeparam name="TKey">Type of the key</typeparam> /// <typeparam name="TKey">Type of the key</typeparam>
/// <typeparam name="TValue">Type of the value</typeparam> /// <typeparam name="TValue">Type of the value</typeparam>
/// <returns>Value if found, default if can not found.</returns> /// <returns>Value if found, default if can not found.</returns>
public static TValue GetOrAdd<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary, TKey key, Func<TValue> factory) public static TValue GetOrAdd<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary, TKey key, Func<TValue> factory) where TKey : notnull
{ {
return dictionary.GetOrAdd(key, k => factory()); return dictionary.GetOrAdd(key, k => factory());
} }
@ -138,7 +138,7 @@ public static class AbpDictionaryExtensions
public static dynamic ConvertToDynamicObject(this Dictionary<string, object> dictionary) public static dynamic ConvertToDynamicObject(this Dictionary<string, object> dictionary)
{ {
var expandoObject = new ExpandoObject(); var expandoObject = new ExpandoObject();
var expendObjectCollection = (ICollection<KeyValuePair<string, object>>)expandoObject; var expendObjectCollection = (ICollection<KeyValuePair<string, object>>)expandoObject!;
foreach (var keyValuePair in dictionary) foreach (var keyValuePair in dictionary)
{ {

4
framework/src/Volo.Abp.Core/System/Collections/Generic/AbpListExtensions.cs

@ -196,7 +196,7 @@ public static class AbpListExtensions
public static List<T> SortByDependencies<T>( public static List<T> SortByDependencies<T>(
this IEnumerable<T> source, this IEnumerable<T> source,
Func<T, IEnumerable<T>> getDependencies, Func<T, IEnumerable<T>> getDependencies,
IEqualityComparer<T> comparer = null) IEqualityComparer<T>? comparer = null) where T : notnull
{ {
/* See: http://www.codeproject.com/Articles/869059/Topological-sorting-in-Csharp /* See: http://www.codeproject.com/Articles/869059/Topological-sorting-in-Csharp
* http://en.wikipedia.org/wiki/Topological_sorting * http://en.wikipedia.org/wiki/Topological_sorting
@ -222,7 +222,7 @@ public static class AbpListExtensions
/// <param name="sorted">List with the sortet items</param> /// <param name="sorted">List with the sortet items</param>
/// <param name="visited">Dictionary with the visited items</param> /// <param name="visited">Dictionary with the visited items</param>
private static void SortByDependenciesVisit<T>(T item, Func<T, IEnumerable<T>> getDependencies, List<T> sorted, private static void SortByDependenciesVisit<T>(T item, Func<T, IEnumerable<T>> getDependencies, List<T> sorted,
Dictionary<T, bool> visited) Dictionary<T, bool> visited) where T : notnull
{ {
bool inProcess; bool inProcess;
var alreadyVisited = visited.TryGetValue(item, out inProcess); var alreadyVisited = visited.TryGetValue(item, out inProcess);

24
framework/src/Volo.Abp.Core/System/Linq/PredicateOperator.cs

@ -42,7 +42,7 @@ public static class PredicateBuilder
} }
/// <summary> Start an expression </summary> /// <summary> Start an expression </summary>
public static ExpressionStarter<T> New<T>(Expression<Func<T, bool>> expr = null) public static ExpressionStarter<T> New<T>(Expression<Func<T, bool>>? expr = null)
{ {
return new ExpressionStarter<T>(expr); return new ExpressionStarter<T>(expr);
} }
@ -58,7 +58,7 @@ public static class PredicateBuilder
[NotNull] Expression<Func<T, bool>> expr2) [NotNull] Expression<Func<T, bool>> expr2)
{ {
var expr2Body = new RebindParameterVisitor(expr2.Parameters[0], expr1.Parameters[0]).Visit(expr2.Body); var expr2Body = new RebindParameterVisitor(expr2.Parameters[0], expr1.Parameters[0]).Visit(expr2.Body);
return Expression.Lambda<Func<T, bool>>(Expression.OrElse(expr1.Body, expr2Body), expr1.Parameters); return Expression.Lambda<Func<T, bool>>(Expression.OrElse(expr1.Body, expr2Body!), expr1.Parameters);
} }
/// <summary> AND </summary> /// <summary> AND </summary>
@ -66,7 +66,7 @@ public static class PredicateBuilder
[NotNull] Expression<Func<T, bool>> expr2) [NotNull] Expression<Func<T, bool>> expr2)
{ {
var expr2Body = new RebindParameterVisitor(expr2.Parameters[0], expr1.Parameters[0]).Visit(expr2.Body); var expr2Body = new RebindParameterVisitor(expr2.Parameters[0], expr1.Parameters[0]).Visit(expr2.Body);
return Expression.Lambda<Func<T, bool>>(Expression.AndAlso(expr1.Body, expr2Body), expr1.Parameters); return Expression.Lambda<Func<T, bool>>(Expression.AndAlso(expr1.Body, expr2Body!), expr1.Parameters);
} }
/// <summary> /// <summary>
@ -120,16 +120,16 @@ public class ExpressionStarter<T>
} }
} }
public ExpressionStarter(Expression<Func<T, bool>> exp) : this(false) public ExpressionStarter(Expression<Func<T, bool>>? exp) : this(false)
{ {
_predicate = exp; _predicate = exp;
} }
/// <summary>The actual Predicate. It can only be set by calling Start.</summary> /// <summary>The actual Predicate. It can only be set by calling Start.</summary>
private Expression<Func<T, bool>> Predicate => private Expression<Func<T, bool>> Predicate =>
(IsStarted || !UseDefaultExpression) ? _predicate : DefaultExpression; ((IsStarted || !UseDefaultExpression) ? _predicate : DefaultExpression)!;
private Expression<Func<T, bool>> _predicate; private Expression<Func<T, bool>>? _predicate;
/// <summary>Determines if the predicate is started.</summary> /// <summary>Determines if the predicate is started.</summary>
public bool IsStarted => _predicate != null; public bool IsStarted => _predicate != null;
@ -138,7 +138,7 @@ public class ExpressionStarter<T>
public bool UseDefaultExpression => DefaultExpression != null; public bool UseDefaultExpression => DefaultExpression != null;
/// <summary>The default expression</summary> /// <summary>The default expression</summary>
public Expression<Func<T, bool>> DefaultExpression { get; set; } public Expression<Func<T, bool>>? DefaultExpression { get; set; }
/// <summary>Set the Expression predicate</summary> /// <summary>Set the Expression predicate</summary>
/// <param name="exp">The first expression</param> /// <param name="exp">The first expression</param>
@ -165,7 +165,7 @@ public class ExpressionStarter<T>
} }
/// <summary> Show predicate string </summary> /// <summary> Show predicate string </summary>
public override string ToString() public override string? ToString()
{ {
return Predicate?.ToString(); return Predicate?.ToString();
} }
@ -176,7 +176,7 @@ public class ExpressionStarter<T>
/// Allows this object to be implicitely converted to an Expression{Func{T, bool}}. /// Allows this object to be implicitely converted to an Expression{Func{T, bool}}.
/// </summary> /// </summary>
/// <param name="right"></param> /// <param name="right"></param>
public static implicit operator Expression<Func<T, bool>>(ExpressionStarter<T> right) public static implicit operator Expression<Func<T, bool>>?(ExpressionStarter<T>? right)
{ {
return right?.Predicate; return right?.Predicate;
} }
@ -185,7 +185,7 @@ public class ExpressionStarter<T>
/// Allows this object to be implicitely converted to an Expression{Func{T, bool}}. /// Allows this object to be implicitely converted to an Expression{Func{T, bool}}.
/// </summary> /// </summary>
/// <param name="right"></param> /// <param name="right"></param>
public static implicit operator Func<T, bool>(ExpressionStarter<T> right) public static implicit operator Func<T, bool>?(ExpressionStarter<T>? right)
{ {
return right == null ? null : return right == null ? null :
(right.IsStarted || right.UseDefaultExpression) ? right.Predicate.Compile() : null; (right.IsStarted || right.UseDefaultExpression) ? right.Predicate.Compile() : null;
@ -195,7 +195,7 @@ public class ExpressionStarter<T>
/// Allows this object to be implicitely converted to an Expression{Func{T, bool}}. /// Allows this object to be implicitely converted to an Expression{Func{T, bool}}.
/// </summary> /// </summary>
/// <param name="right"></param> /// <param name="right"></param>
public static implicit operator ExpressionStarter<T>(Expression<Func<T, bool>> right) public static implicit operator ExpressionStarter<T>?(Expression<Func<T, bool>>? right)
{ {
return right == null ? null : new ExpressionStarter<T>(right); return right == null ? null : new ExpressionStarter<T>(right);
} }
@ -240,7 +240,7 @@ public class ExpressionStarter<T>
#if !(NET35) #if !(NET35)
/// <summary></summary> /// <summary></summary>
public string Name => Predicate.Name; public string? Name => Predicate.Name;
/// <summary></summary> /// <summary></summary>
public Type ReturnType => Predicate.ReturnType; public Type ReturnType => Predicate.ReturnType;

2
framework/src/Volo.Abp.Core/System/Reflection/AbpAssemblyExtensions.cs

@ -6,6 +6,6 @@ public static class AbpAssemblyExtensions
{ {
public static string GetFileVersion(this Assembly assembly) public static string GetFileVersion(this Assembly assembly)
{ {
return FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion; return FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion!;
} }
} }

6
framework/src/Volo.Abp.Core/System/Reflection/AbpMemberInfoExtensions.cs

@ -14,7 +14,7 @@ public static class AbpMemberInfoExtensions
/// <param name="memberInfo">The member that will be checked for the attribute</param> /// <param name="memberInfo">The member that will be checked for the attribute</param>
/// <param name="inherit">Include inherited attributes</param> /// <param name="inherit">Include inherited attributes</param>
/// <returns>Returns the attribute object if found. Returns null if not found.</returns> /// <returns>Returns the attribute object if found. Returns null if not found.</returns>
public static TAttribute GetSingleAttributeOrNull<TAttribute>(this MemberInfo memberInfo, bool inherit = true) public static TAttribute? GetSingleAttributeOrNull<TAttribute>(this MemberInfo memberInfo, bool inherit = true)
where TAttribute : Attribute where TAttribute : Attribute
{ {
if (memberInfo == null) if (memberInfo == null)
@ -32,7 +32,7 @@ public static class AbpMemberInfoExtensions
} }
public static TAttribute GetSingleAttributeOfTypeOrBaseTypesOrNull<TAttribute>(this Type type, bool inherit = true) public static TAttribute? GetSingleAttributeOfTypeOrBaseTypesOrNull<TAttribute>(this Type type, bool inherit = true)
where TAttribute : Attribute where TAttribute : Attribute
{ {
var attr = type.GetTypeInfo().GetSingleAttributeOrNull<TAttribute>(); var attr = type.GetTypeInfo().GetSingleAttributeOrNull<TAttribute>();
@ -46,6 +46,6 @@ public static class AbpMemberInfoExtensions
return null; return null;
} }
return type.GetTypeInfo().BaseType.GetSingleAttributeOfTypeOrBaseTypesOrNull<TAttribute>(inherit); return type.GetTypeInfo().BaseType?.GetSingleAttributeOfTypeOrBaseTypesOrNull<TAttribute>(inherit);
} }
} }

1
framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj

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

16
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs

@ -19,13 +19,13 @@ public abstract class AbpApplicationBase : IAbpApplication
[NotNull] [NotNull]
public Type StartupModuleType { get; } public Type StartupModuleType { get; }
public IServiceProvider ServiceProvider { get; private set; } public IServiceProvider ServiceProvider { get; private set; } = default!;
public IServiceCollection Services { get; } public IServiceCollection Services { get; }
public IReadOnlyList<IAbpModuleDescriptor> Modules { get; } public IReadOnlyList<IAbpModuleDescriptor> Modules { get; }
public string ApplicationName { get; } public string? ApplicationName { get; }
public string InstanceId { get; } = Guid.NewGuid().ToString(); public string InstanceId { get; } = Guid.NewGuid().ToString();
@ -34,7 +34,7 @@ public abstract class AbpApplicationBase : IAbpApplication
internal AbpApplicationBase( internal AbpApplicationBase(
[NotNull] Type startupModuleType, [NotNull] Type startupModuleType,
[NotNull] IServiceCollection services, [NotNull] IServiceCollection services,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction) Action<AbpApplicationCreationOptions>? optionsAction)
{ {
Check.NotNull(startupModuleType, nameof(startupModuleType)); Check.NotNull(startupModuleType, nameof(startupModuleType));
Check.NotNull(services, nameof(services)); Check.NotNull(services, nameof(services));
@ -224,7 +224,7 @@ public abstract class AbpApplicationBase : IAbpApplication
{ {
if (module.Instance is AbpModule abpModule) if (module.Instance is AbpModule abpModule)
{ {
abpModule.ServiceConfigurationContext = null; abpModule.ServiceConfigurationContext = null!;
} }
} }
@ -315,7 +315,7 @@ public abstract class AbpApplicationBase : IAbpApplication
{ {
if (module.Instance is AbpModule abpModule) if (module.Instance is AbpModule abpModule)
{ {
abpModule.ServiceConfigurationContext = null; abpModule.ServiceConfigurationContext = null!;
} }
} }
@ -324,11 +324,11 @@ public abstract class AbpApplicationBase : IAbpApplication
TryToSetEnvironment(Services); TryToSetEnvironment(Services);
} }
private static string GetApplicationName(AbpApplicationCreationOptions options) private static string? GetApplicationName(AbpApplicationCreationOptions options)
{ {
if (!string.IsNullOrWhiteSpace(options.ApplicationName)) if (!string.IsNullOrWhiteSpace(options.ApplicationName))
{ {
return options.ApplicationName; return options.ApplicationName!;
} }
var configuration = options.Services.GetConfigurationOrNull(); var configuration = options.Services.GetConfigurationOrNull();
@ -337,7 +337,7 @@ public abstract class AbpApplicationBase : IAbpApplication
var appNameConfig = configuration["ApplicationName"]; var appNameConfig = configuration["ApplicationName"];
if (!string.IsNullOrWhiteSpace(appNameConfig)) if (!string.IsNullOrWhiteSpace(appNameConfig))
{ {
return appNameConfig; return appNameConfig!;
} }
} }

6
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationCreationOptions.cs

@ -21,11 +21,9 @@ public class AbpApplicationCreationOptions
public bool SkipConfigureServices { get; set; } public bool SkipConfigureServices { get; set; }
[CanBeNull] public string? ApplicationName { get; set; }
public string ApplicationName { get; set; }
[CanBeNull] public string? Environment { get; set; }
public string Environment { get; set; }
public AbpApplicationCreationOptions([NotNull] IServiceCollection services) public AbpApplicationCreationOptions([NotNull] IServiceCollection services)
{ {

16
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationFactory.cs

@ -9,7 +9,7 @@ namespace Volo.Abp;
public static class AbpApplicationFactory public static class AbpApplicationFactory
{ {
public async static Task<IAbpApplicationWithInternalServiceProvider> CreateAsync<TStartupModule>( public async static Task<IAbpApplicationWithInternalServiceProvider> CreateAsync<TStartupModule>(
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction = null) Action<AbpApplicationCreationOptions>? optionsAction = null)
where TStartupModule : IAbpModule where TStartupModule : IAbpModule
{ {
var app = Create(typeof(TStartupModule), options => var app = Create(typeof(TStartupModule), options =>
@ -23,7 +23,7 @@ public static class AbpApplicationFactory
public async static Task<IAbpApplicationWithInternalServiceProvider> CreateAsync( public async static Task<IAbpApplicationWithInternalServiceProvider> CreateAsync(
[NotNull] Type startupModuleType, [NotNull] Type startupModuleType,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction = null) Action<AbpApplicationCreationOptions>? optionsAction = null)
{ {
var app = new AbpApplicationWithInternalServiceProvider(startupModuleType, options => var app = new AbpApplicationWithInternalServiceProvider(startupModuleType, options =>
{ {
@ -36,7 +36,7 @@ public static class AbpApplicationFactory
public async static Task<IAbpApplicationWithExternalServiceProvider> CreateAsync<TStartupModule>( public async static Task<IAbpApplicationWithExternalServiceProvider> CreateAsync<TStartupModule>(
[NotNull] IServiceCollection services, [NotNull] IServiceCollection services,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction = null) Action<AbpApplicationCreationOptions>? optionsAction = null)
where TStartupModule : IAbpModule where TStartupModule : IAbpModule
{ {
var app = Create(typeof(TStartupModule), services, options => var app = Create(typeof(TStartupModule), services, options =>
@ -51,7 +51,7 @@ public static class AbpApplicationFactory
public async static Task<IAbpApplicationWithExternalServiceProvider> CreateAsync( public async static Task<IAbpApplicationWithExternalServiceProvider> CreateAsync(
[NotNull] Type startupModuleType, [NotNull] Type startupModuleType,
[NotNull] IServiceCollection services, [NotNull] IServiceCollection services,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction = null) Action<AbpApplicationCreationOptions>? optionsAction = null)
{ {
var app = new AbpApplicationWithExternalServiceProvider(startupModuleType, services, options => var app = new AbpApplicationWithExternalServiceProvider(startupModuleType, services, options =>
{ {
@ -63,7 +63,7 @@ public static class AbpApplicationFactory
} }
public static IAbpApplicationWithInternalServiceProvider Create<TStartupModule>( public static IAbpApplicationWithInternalServiceProvider Create<TStartupModule>(
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction = null) Action<AbpApplicationCreationOptions>? optionsAction = null)
where TStartupModule : IAbpModule where TStartupModule : IAbpModule
{ {
return Create(typeof(TStartupModule), optionsAction); return Create(typeof(TStartupModule), optionsAction);
@ -71,14 +71,14 @@ public static class AbpApplicationFactory
public static IAbpApplicationWithInternalServiceProvider Create( public static IAbpApplicationWithInternalServiceProvider Create(
[NotNull] Type startupModuleType, [NotNull] Type startupModuleType,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction = null) Action<AbpApplicationCreationOptions>? optionsAction = null)
{ {
return new AbpApplicationWithInternalServiceProvider(startupModuleType, optionsAction); return new AbpApplicationWithInternalServiceProvider(startupModuleType, optionsAction);
} }
public static IAbpApplicationWithExternalServiceProvider Create<TStartupModule>( public static IAbpApplicationWithExternalServiceProvider Create<TStartupModule>(
[NotNull] IServiceCollection services, [NotNull] IServiceCollection services,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction = null) Action<AbpApplicationCreationOptions>? optionsAction = null)
where TStartupModule : IAbpModule where TStartupModule : IAbpModule
{ {
return Create(typeof(TStartupModule), services, optionsAction); return Create(typeof(TStartupModule), services, optionsAction);
@ -87,7 +87,7 @@ public static class AbpApplicationFactory
public static IAbpApplicationWithExternalServiceProvider Create( public static IAbpApplicationWithExternalServiceProvider Create(
[NotNull] Type startupModuleType, [NotNull] Type startupModuleType,
[NotNull] IServiceCollection services, [NotNull] IServiceCollection services,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction = null) Action<AbpApplicationCreationOptions>? optionsAction = null)
{ {
return new AbpApplicationWithExternalServiceProvider(startupModuleType, services, optionsAction); return new AbpApplicationWithExternalServiceProvider(startupModuleType, services, optionsAction);
} }

3
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationWithExternalServiceProvider.cs

@ -10,7 +10,7 @@ internal class AbpApplicationWithExternalServiceProvider : AbpApplicationBase, I
public AbpApplicationWithExternalServiceProvider( public AbpApplicationWithExternalServiceProvider(
[NotNull] Type startupModuleType, [NotNull] Type startupModuleType,
[NotNull] IServiceCollection services, [NotNull] IServiceCollection services,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction Action<AbpApplicationCreationOptions>? optionsAction
) : base( ) : base(
startupModuleType, startupModuleType,
services, services,
@ -23,6 +23,7 @@ internal class AbpApplicationWithExternalServiceProvider : AbpApplicationBase, I
{ {
Check.NotNull(serviceProvider, nameof(serviceProvider)); Check.NotNull(serviceProvider, nameof(serviceProvider));
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (ServiceProvider != null) if (ServiceProvider != null)
{ {
if (ServiceProvider != serviceProvider) if (ServiceProvider != serviceProvider)

9
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationWithInternalServiceProvider.cs

@ -7,11 +7,11 @@ namespace Volo.Abp;
internal class AbpApplicationWithInternalServiceProvider : AbpApplicationBase, IAbpApplicationWithInternalServiceProvider internal class AbpApplicationWithInternalServiceProvider : AbpApplicationBase, IAbpApplicationWithInternalServiceProvider
{ {
public IServiceScope ServiceScope { get; private set; } public IServiceScope? ServiceScope { get; private set; }
public AbpApplicationWithInternalServiceProvider( public AbpApplicationWithInternalServiceProvider(
[NotNull] Type startupModuleType, [NotNull] Type startupModuleType,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction Action<AbpApplicationCreationOptions>? optionsAction
) : this( ) : this(
startupModuleType, startupModuleType,
new ServiceCollection(), new ServiceCollection(),
@ -23,7 +23,7 @@ internal class AbpApplicationWithInternalServiceProvider : AbpApplicationBase, I
private AbpApplicationWithInternalServiceProvider( private AbpApplicationWithInternalServiceProvider(
[NotNull] Type startupModuleType, [NotNull] Type startupModuleType,
[NotNull] IServiceCollection services, [NotNull] IServiceCollection services,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction Action<AbpApplicationCreationOptions>? optionsAction
) : base( ) : base(
startupModuleType, startupModuleType,
services, services,
@ -34,6 +34,7 @@ internal class AbpApplicationWithInternalServiceProvider : AbpApplicationBase, I
public IServiceProvider CreateServiceProvider() public IServiceProvider CreateServiceProvider()
{ {
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (ServiceProvider != null) if (ServiceProvider != null)
{ {
return ServiceProvider; return ServiceProvider;
@ -42,7 +43,7 @@ internal class AbpApplicationWithInternalServiceProvider : AbpApplicationBase, I
ServiceScope = Services.BuildServiceProviderFromFactory().CreateScope(); ServiceScope = Services.BuildServiceProviderFromFactory().CreateScope();
SetServiceProvider(ServiceScope.ServiceProvider); SetServiceProvider(ServiceScope.ServiceProvider);
return ServiceProvider; return ServiceProvider!;
} }
public async Task InitializeAsync() public async Task InitializeAsync()

2
framework/src/Volo.Abp.Core/Volo/Abp/AbpHostEnvironment.cs

@ -2,5 +2,5 @@
public class AbpHostEnvironment : IAbpHostEnvironment public class AbpHostEnvironment : IAbpHostEnvironment
{ {
public string EnvironmentName { get; set; } public string? EnvironmentName { get; set; }
} }

2
framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleContext.cs

@ -14,7 +14,7 @@ public class BundleContext
} }
public void Add(string source, bool excludeFromBundle = false, public void Add(string source, bool excludeFromBundle = false,
Dictionary<string, string> additionalProperties = null) Dictionary<string, string>? additionalProperties = null)
{ {
var bundleDefinition = new BundleDefinition var bundleDefinition = new BundleDefinition
{ {

2
framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleDefinition.cs

@ -4,7 +4,7 @@ namespace Volo.Abp.Bundling;
public class BundleDefinition public class BundleDefinition
{ {
public string Source { get; set; } public string Source { get; set; } = default!;
public Dictionary<string, string> AdditionalProperties { get; set; } public Dictionary<string, string> AdditionalProperties { get; set; }

12
framework/src/Volo.Abp.Core/Volo/Abp/BusinessException.cs

@ -13,17 +13,17 @@ public class BusinessException : Exception,
IHasErrorDetails, IHasErrorDetails,
IHasLogLevel IHasLogLevel
{ {
public string Code { get; set; } public string? Code { get; set; }
public string Details { get; set; } public string? Details { get; set; }
public LogLevel LogLevel { get; set; } public LogLevel LogLevel { get; set; }
public BusinessException( public BusinessException(
string code = null, string? code = null,
string message = null, string? message = null,
string details = null, string? details = null,
Exception innerException = null, Exception? innerException = null,
LogLevel logLevel = LogLevel.Warning) LogLevel logLevel = LogLevel.Warning)
: base(message, innerException) : base(message, innerException)
{ {

6
framework/src/Volo.Abp.Core/Volo/Abp/Check.cs

@ -136,8 +136,8 @@ public static class Check
return type; return type;
} }
public static string Length( public static string? Length(
[CanBeNull] string value, string? value,
[InvokerParameterName][NotNull] string parameterName, [InvokerParameterName][NotNull] string parameterName,
int maxLength, int maxLength,
int minLength = 0) int minLength = 0)
@ -149,7 +149,7 @@ public static class Check
throw new ArgumentException(parameterName + " can not be null or empty!", parameterName); throw new ArgumentException(parameterName + " can not be null or empty!", parameterName);
} }
if (value.Length < minLength) if (value!.Length < minLength)
{ {
throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName); throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName);
} }

2
framework/src/Volo.Abp.Core/Volo/Abp/Content/IRemoteStreamContent.cs

@ -5,7 +5,7 @@ namespace Volo.Abp.Content;
public interface IRemoteStreamContent : IDisposable public interface IRemoteStreamContent : IDisposable
{ {
string FileName { get; } string? FileName { get; }
string ContentType { get; } string ContentType { get; }

4
framework/src/Volo.Abp.Core/Volo/Abp/Content/RemoteStreamContent.cs

@ -8,13 +8,13 @@ public class RemoteStreamContent : IRemoteStreamContent
private readonly bool _disposeStream; private readonly bool _disposeStream;
private bool _disposed; private bool _disposed;
public virtual string FileName { get; } public virtual string? FileName { get; }
public virtual string ContentType { get; } = "application/octet-stream"; public virtual string ContentType { get; } = "application/octet-stream";
public virtual long? ContentLength { get; } public virtual long? ContentLength { get; }
public RemoteStreamContent(Stream stream, string fileName = null, string contentType = null, long? readOnlyLength = null, bool disposeStream = true) public RemoteStreamContent(Stream stream, string? fileName = null, string? contentType = null, long? readOnlyLength = null, bool disposeStream = true)
{ {
_stream = stream; _stream = stream;

6
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/AbpLazyServiceProvider.cs

@ -28,12 +28,12 @@ public class AbpLazyServiceProvider :
return this.GetRequiredService(serviceType); return this.GetRequiredService(serviceType);
} }
public virtual T LazyGetService<T>() public virtual T? LazyGetService<T>()
{ {
return (T)LazyGetService(typeof(T)); return (T?)LazyGetService(typeof(T));
} }
public virtual object LazyGetService(Type serviceType) public virtual object? LazyGetService(Type serviceType)
{ {
return GetService(serviceType); return GetService(serviceType);
} }

16
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/CachedServiceProviderBase.cs

@ -6,26 +6,26 @@ namespace Volo.Abp.DependencyInjection;
public abstract class CachedServiceProviderBase : ICachedServiceProviderBase public abstract class CachedServiceProviderBase : ICachedServiceProviderBase
{ {
protected IServiceProvider ServiceProvider { get; } protected IServiceProvider ServiceProvider { get; }
protected ConcurrentDictionary<Type, Lazy<object>> CachedServices { get; } protected ConcurrentDictionary<Type, Lazy<object?>> CachedServices { get; }
protected CachedServiceProviderBase(IServiceProvider serviceProvider) protected CachedServiceProviderBase(IServiceProvider serviceProvider)
{ {
ServiceProvider = serviceProvider; ServiceProvider = serviceProvider;
CachedServices = new ConcurrentDictionary<Type, Lazy<object>>(); CachedServices = new ConcurrentDictionary<Type, Lazy<object?>>();
CachedServices.TryAdd(typeof(IServiceProvider), new Lazy<object>(() => ServiceProvider)); CachedServices.TryAdd(typeof(IServiceProvider), new Lazy<object?>(() => ServiceProvider));
} }
public virtual object GetService(Type serviceType) public virtual object? GetService(Type serviceType)
{ {
return CachedServices.GetOrAdd( return CachedServices.GetOrAdd(
serviceType, serviceType,
_ => new Lazy<object>(() => ServiceProvider.GetService(serviceType)) _ => new Lazy<object?>(() => ServiceProvider.GetService(serviceType))
).Value; ).Value;
} }
public T GetService<T>(T defaultValue) public T GetService<T>(T defaultValue)
{ {
return (T)GetService(typeof(T), defaultValue); return (T)GetService(typeof(T), defaultValue!);
} }
public object GetService(Type serviceType, object defaultValue) public object GetService(Type serviceType, object defaultValue)
@ -42,7 +42,7 @@ public abstract class CachedServiceProviderBase : ICachedServiceProviderBase
{ {
return CachedServices.GetOrAdd( return CachedServices.GetOrAdd(
serviceType, serviceType,
_ => new Lazy<object>(() => factory(ServiceProvider)) _ => new Lazy<object?>(() => factory(ServiceProvider))
).Value; ).Value!;
} }
} }

8
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ConventionalRegistrarBase.cs

@ -52,12 +52,12 @@ public abstract class ConventionalRegistrarBase : IConventionalRegistrar
} }
} }
protected virtual DependencyAttribute GetDependencyAttributeOrNull(Type type) protected virtual DependencyAttribute? GetDependencyAttributeOrNull(Type type)
{ {
return type.GetCustomAttribute<DependencyAttribute>(true); return type.GetCustomAttribute<DependencyAttribute>(true);
} }
protected virtual ServiceLifetime? GetLifeTimeOrNull(Type type, [CanBeNull] DependencyAttribute dependencyAttribute) protected virtual ServiceLifetime? GetLifeTimeOrNull(Type type, DependencyAttribute? dependencyAttribute)
{ {
return dependencyAttribute?.Lifetime ?? GetServiceLifetimeFromClassHierarchy(type) ?? GetDefaultLifeTimeOrNull(type); return dependencyAttribute?.Lifetime ?? GetServiceLifetimeFromClassHierarchy(type) ?? GetDefaultLifeTimeOrNull(type);
} }
@ -110,7 +110,7 @@ public abstract class ConventionalRegistrarBase : IConventionalRegistrar
{ {
return ServiceDescriptor.Describe( return ServiceDescriptor.Describe(
exposingServiceType, exposingServiceType,
provider => provider.GetService(redirectedType), provider => provider.GetService(redirectedType)!,
lifeTime lifeTime
); );
} }
@ -123,7 +123,7 @@ public abstract class ConventionalRegistrarBase : IConventionalRegistrar
); );
} }
protected virtual Type GetRedirectedTypeOrNull( protected virtual Type? GetRedirectedTypeOrNull(
Type implementationType, Type implementationType,
Type exposingServiceType, Type exposingServiceType,
List<Type> allExposingServiceTypes) List<Type> allExposingServiceTypes)

4
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/IAbpLazyServiceProvider.cs

@ -24,13 +24,13 @@ public interface IAbpLazyServiceProvider : ICachedServiceProviderBase
/// This method is equivalent of the GetService method. /// This method is equivalent of the GetService method.
/// It does exists for backward compatibility. /// It does exists for backward compatibility.
/// </summary> /// </summary>
T LazyGetService<T>(); T? LazyGetService<T>();
/// <summary> /// <summary>
/// This method is equivalent of the GetService method. /// This method is equivalent of the GetService method.
/// It does exists for backward compatibility. /// It does exists for backward compatibility.
/// </summary> /// </summary>
object LazyGetService(Type serviceType); object? LazyGetService(Type serviceType);
/// <summary> /// <summary>
/// This method is equivalent of the <see cref="ICachedServiceProviderBase.GetService{T}(T)"/> method. /// This method is equivalent of the <see cref="ICachedServiceProviderBase.GetService{T}(T)"/> method.

3
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/IObjectAccessor.cs

@ -4,6 +4,5 @@ namespace Volo.Abp.DependencyInjection;
public interface IObjectAccessor<out T> public interface IObjectAccessor<out T>
{ {
[CanBeNull] T? Value { get; }
T Value { get; }
} }

4
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ObjectAccessor.cs

@ -4,14 +4,14 @@ namespace Volo.Abp.DependencyInjection;
public class ObjectAccessor<T> : IObjectAccessor<T> public class ObjectAccessor<T> : IObjectAccessor<T>
{ {
public T Value { get; set; } public T? Value { get; set; }
public ObjectAccessor() public ObjectAccessor()
{ {
} }
public ObjectAccessor([CanBeNull] T obj) public ObjectAccessor(T? obj)
{ {
Value = obj; Value = obj;
} }

4
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/RootServiceProvider.cs

@ -9,10 +9,10 @@ public class RootServiceProvider : IRootServiceProvider, ISingletonDependency
public RootServiceProvider(IObjectAccessor<IServiceProvider> objectAccessor) public RootServiceProvider(IObjectAccessor<IServiceProvider> objectAccessor)
{ {
ServiceProvider = objectAccessor.Value; ServiceProvider = objectAccessor.Value!;
} }
public virtual object GetService(Type serviceType) public virtual object? GetService(Type serviceType)
{ {
return ServiceProvider.GetService(serviceType); return ServiceProvider.GetService(serviceType);
} }

8
framework/src/Volo.Abp.Core/Volo/Abp/DisposeAction.cs

@ -37,8 +37,7 @@ public class DisposeAction<T> : IDisposable
{ {
private readonly Action<T> _action; private readonly Action<T> _action;
[CanBeNull] private readonly T? _parameter;
private readonly T _parameter;
/// <summary> /// <summary>
/// Creates a new <see cref="DisposeAction"/> object. /// Creates a new <see cref="DisposeAction"/> object.
@ -55,6 +54,9 @@ public class DisposeAction<T> : IDisposable
public void Dispose() public void Dispose()
{ {
_action(_parameter); if (_parameter != null)
{
_action(_parameter);
}
} }
} }

13
framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/ProxyHelper.cs

@ -28,7 +28,7 @@ public static class ProxyHelper
return obj; return obj;
} }
return targetField.GetValue(obj); return targetField.GetValue(obj)!;
} }
public static Type GetUnProxiedType(object obj) public static Type GetUnProxiedType(object obj)
@ -36,15 +36,12 @@ public static class ProxyHelper
if (obj.GetType().Namespace == ProxyNamespace) if (obj.GetType().Namespace == ProxyNamespace)
{ {
var target = UnProxy(obj); var target = UnProxy(obj);
if (target != null) if (target == obj)
{ {
if (target == obj) return obj.GetType().GetTypeInfo().BaseType!;
{
return obj.GetType().GetTypeInfo().BaseType;
}
return target.GetType();
} }
return target.GetType();
} }
return obj.GetType(); return obj.GetType();

2
framework/src/Volo.Abp.Core/Volo/Abp/ExceptionHandling/IHasErrorCode.cs

@ -2,5 +2,5 @@
public interface IHasErrorCode public interface IHasErrorCode
{ {
string Code { get; } string? Code { get; }
} }

2
framework/src/Volo.Abp.Core/Volo/Abp/ExceptionHandling/IHasErrorDetails.cs

@ -2,5 +2,5 @@ namespace Volo.Abp.ExceptionHandling;
public interface IHasErrorDetails public interface IHasErrorDetails
{ {
string Details { get; } string? Details { get; }
} }

2
framework/src/Volo.Abp.Core/Volo/Abp/IAbpHostEnvironment.cs

@ -2,5 +2,5 @@
public interface IAbpHostEnvironment public interface IAbpHostEnvironment
{ {
string EnvironmentName { get; set; } string? EnvironmentName { get; set; }
} }

3
framework/src/Volo.Abp.Core/Volo/Abp/IApplicationInfoAccessor.cs

@ -9,8 +9,7 @@ public interface IApplicationInfoAccessor
/// This is useful for systems with multiple applications, to distinguish /// This is useful for systems with multiple applications, to distinguish
/// resources of the applications located together. /// resources of the applications located together.
/// </summary> /// </summary>
[CanBeNull] string? ApplicationName { get; }
string ApplicationName { get; }
/// <summary> /// <summary>
/// A unique identifier for this application instance. /// A unique identifier for this application instance.

9
framework/src/Volo.Abp.Core/Volo/Abp/IO/FileHelper.cs

@ -36,8 +36,7 @@ public static class FileHelper
/// Returns extension without dot. /// Returns extension without dot.
/// Returns null if given <paramref name="fileNameWithExtension"></paramref> does not include dot. /// Returns null if given <paramref name="fileNameWithExtension"></paramref> does not include dot.
/// </returns> /// </returns>
[CanBeNull] public static string? GetExtension([NotNull] string fileNameWithExtension)
public static string GetExtension([NotNull] string fileNameWithExtension)
{ {
Check.NotNull(fileNameWithExtension, nameof(fileNameWithExtension)); Check.NotNull(fileNameWithExtension, nameof(fileNameWithExtension));
@ -90,7 +89,7 @@ public static class FileHelper
/// <param name="fileOptions">Indicates FileStream options. Default is Asynchronous (The file is to be used for asynchronous reading.) and SequentialScan (The file is to be accessed sequentially from beginning to end.) </param> /// <param name="fileOptions">Indicates FileStream options. Default is Asynchronous (The file is to be used for asynchronous reading.) and SequentialScan (The file is to be accessed sequentially from beginning to end.) </param>
/// <returns>A string containing all lines of the file.</returns> /// <returns>A string containing all lines of the file.</returns>
public static async Task<string[]> ReadAllLinesAsync(string path, public static async Task<string[]> ReadAllLinesAsync(string path,
Encoding encoding = null, Encoding? encoding = null,
FileMode fileMode = FileMode.Open, FileMode fileMode = FileMode.Open,
FileAccess fileAccess = FileAccess.Read, FileAccess fileAccess = FileAccess.Read,
FileShare fileShare = FileShare.Read, FileShare fileShare = FileShare.Read,
@ -114,7 +113,7 @@ public static class FileHelper
{ {
using (var reader = new StreamReader(stream, encoding)) using (var reader = new StreamReader(stream, encoding))
{ {
string line; string? line;
while ((line = await reader.ReadLineAsync()) != null) while ((line = await reader.ReadLineAsync()) != null)
{ {
lines.Add(line); lines.Add(line);
@ -134,6 +133,6 @@ public static class FileHelper
{ {
var content = await ReadAllBytesAsync(path); var content = await ReadAllBytesAsync(path);
return StringHelper.ConvertFromBytesWithoutBom(content); return StringHelper.ConvertFromBytesWithoutBom(content)!;
} }
} }

4
framework/src/Volo.Abp.Core/Volo/Abp/Localization/CultureHelper.cs

@ -7,7 +7,7 @@ namespace Volo.Abp.Localization;
public static class CultureHelper public static class CultureHelper
{ {
public static IDisposable Use([NotNull] string culture, string uiCulture = null) public static IDisposable Use([NotNull] string culture, string? uiCulture = null)
{ {
Check.NotNull(culture, nameof(culture)); Check.NotNull(culture, nameof(culture));
@ -19,7 +19,7 @@ public static class CultureHelper
); );
} }
public static IDisposable Use([NotNull] CultureInfo culture, CultureInfo uiCulture = null) public static IDisposable Use([NotNull] CultureInfo culture, CultureInfo? uiCulture = null)
{ {
Check.NotNull(culture, nameof(culture)); Check.NotNull(culture, nameof(culture));

6
framework/src/Volo.Abp.Core/Volo/Abp/Logging/AbpInitLogEntry.cs

@ -9,11 +9,11 @@ public class AbpInitLogEntry
public EventId EventId { get; set; } public EventId EventId { get; set; }
public object State { get; set; } public object State { get; set; } = default!;
public Exception Exception { get; set; } public Exception? Exception { get; set; }
public Func<object, Exception, string> Formatter { get; set; } public Func<object, Exception?, string> Formatter { get; set; } = default!;
public string Message => Formatter(State, Exception); public string Message => Formatter(State, Exception);
} }

6
framework/src/Volo.Abp.Core/Volo/Abp/Logging/DefaultInitLogger.cs

@ -13,13 +13,13 @@ public class DefaultInitLogger<T> : IInitLogger<T>
Entries = new List<AbpInitLogEntry>(); Entries = new List<AbpInitLogEntry>();
} }
public virtual void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) public virtual void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{ {
Entries.Add(new AbpInitLogEntry Entries.Add(new AbpInitLogEntry
{ {
LogLevel = logLevel, LogLevel = logLevel,
EventId = eventId, EventId = eventId,
State = state, State = state!,
Exception = exception, Exception = exception,
Formatter = (s, e) => formatter((TState)s, e), Formatter = (s, e) => formatter((TState)s, e),
}); });
@ -30,7 +30,7 @@ public class DefaultInitLogger<T> : IInitLogger<T>
return logLevel != LogLevel.None; return logLevel != LogLevel.None;
} }
public virtual IDisposable BeginScope<TState>(TState state) public virtual IDisposable BeginScope<TState>(TState state) where TState : notnull
{ {
return NullDisposable.Instance; return NullDisposable.Instance;
} }

2
framework/src/Volo.Abp.Core/Volo/Abp/Modularity/AbpModule.cs

@ -29,7 +29,7 @@ public abstract class AbpModule :
internal set => _serviceConfigurationContext = value; internal set => _serviceConfigurationContext = value;
} }
private ServiceConfigurationContext _serviceConfigurationContext; private ServiceConfigurationContext? _serviceConfigurationContext;
public virtual Task PreConfigureServicesAsync(ServiceConfigurationContext context) public virtual Task PreConfigureServicesAsync(ServiceConfigurationContext context)
{ {

2
framework/src/Volo.Abp.Core/Volo/Abp/Modularity/DependsOnAttribute.cs

@ -12,7 +12,7 @@ public class DependsOnAttribute : Attribute, IDependedTypesProvider
[NotNull] [NotNull]
public Type[] DependedTypes { get; } public Type[] DependedTypes { get; }
public DependsOnAttribute(params Type[] dependedTypes) public DependsOnAttribute(params Type[]? dependedTypes)
{ {
DependedTypes = dependedTypes ?? new Type[0]; DependedTypes = dependedTypes ?? new Type[0];
} }

2
framework/src/Volo.Abp.Core/Volo/Abp/Modularity/ModuleLoader.cs

@ -85,7 +85,7 @@ public class ModuleLoader : IModuleLoader
protected virtual IAbpModule CreateAndRegisterModule(IServiceCollection services, Type moduleType) protected virtual IAbpModule CreateAndRegisterModule(IServiceCollection services, Type moduleType)
{ {
var module = (IAbpModule)Activator.CreateInstance(moduleType); var module = (IAbpModule)Activator.CreateInstance(moduleType)!;
services.AddSingleton(moduleType, module); services.AddSingleton(moduleType, module);
return module; return module;
} }

2
framework/src/Volo.Abp.Core/Volo/Abp/Modularity/PlugIns/FilePlugInSource.cs

@ -8,7 +8,7 @@ public class FilePlugInSource : IPlugInSource
{ {
public string[] FilePaths { get; } public string[] FilePaths { get; }
public FilePlugInSource(params string[] filePaths) public FilePlugInSource(params string[]? filePaths)
{ {
FilePaths = filePaths ?? new string[0]; FilePaths = filePaths ?? new string[0];
} }

2
framework/src/Volo.Abp.Core/Volo/Abp/Modularity/PlugIns/FolderPlugInSource.cs

@ -15,7 +15,7 @@ public class FolderPlugInSource : IPlugInSource
public SearchOption SearchOption { get; set; } public SearchOption SearchOption { get; set; }
public Func<string, bool> Filter { get; set; } public Func<string, bool>? Filter { get; set; }
public FolderPlugInSource( public FolderPlugInSource(
[NotNull] string folder, [NotNull] string folder,

2
framework/src/Volo.Abp.Core/Volo/Abp/Modularity/PlugIns/TypePlugInSource.cs

@ -7,7 +7,7 @@ public class TypePlugInSource : IPlugInSource
{ {
private readonly Type[] _moduleTypes; private readonly Type[] _moduleTypes;
public TypePlugInSource(params Type[] moduleTypes) public TypePlugInSource(params Type[]? moduleTypes)
{ {
_moduleTypes = moduleTypes ?? new Type[0]; _moduleTypes = moduleTypes ?? new Type[0];
} }

6
framework/src/Volo.Abp.Core/Volo/Abp/Modularity/ServiceConfigurationContext.cs

@ -8,7 +8,7 @@ public class ServiceConfigurationContext
{ {
public IServiceCollection Services { get; } public IServiceCollection Services { get; }
public IDictionary<string, object> Items { get; } public IDictionary<string, object?> Items { get; }
/// <summary> /// <summary>
/// Gets/sets arbitrary named objects those can be stored during /// Gets/sets arbitrary named objects those can be stored during
@ -19,7 +19,7 @@ public class ServiceConfigurationContext
/// </summary> /// </summary>
/// <param name="key"></param> /// <param name="key"></param>
/// <returns></returns> /// <returns></returns>
public object this[string key] { public object? this[string key] {
get => Items.GetOrDefault(key); get => Items.GetOrDefault(key);
set => Items[key] = value; set => Items[key] = value;
} }
@ -27,6 +27,6 @@ public class ServiceConfigurationContext
public ServiceConfigurationContext([NotNull] IServiceCollection services) public ServiceConfigurationContext([NotNull] IServiceCollection services)
{ {
Services = Check.NotNull(services, nameof(services)); Services = Check.NotNull(services, nameof(services));
Items = new Dictionary<string, object>(); Items = new Dictionary<string, object?>();
} }
} }

4
framework/src/Volo.Abp.Core/Volo/Abp/NameValue.cs

@ -29,12 +29,12 @@ public class NameValue<T>
/// <summary> /// <summary>
/// Name. /// Name.
/// </summary> /// </summary>
public string Name { get; set; } public string Name { get; set; } = default!;
/// <summary> /// <summary>
/// Value. /// Value.
/// </summary> /// </summary>
public T Value { get; set; } public T Value { get; set; } = default!;
public NameValue() public NameValue()
{ {

10
framework/src/Volo.Abp.Core/Volo/Abp/ObjectHelper.cs

@ -9,8 +9,8 @@ namespace Volo.Abp;
public static class ObjectHelper public static class ObjectHelper
{ {
private static readonly ConcurrentDictionary<string, PropertyInfo> CachedObjectProperties = private static readonly ConcurrentDictionary<string, PropertyInfo?> CachedObjectProperties =
new ConcurrentDictionary<string, PropertyInfo>(); new ConcurrentDictionary<string, PropertyInfo?>();
public static void TrySetProperty<TObject, TValue>( public static void TrySetProperty<TObject, TValue>(
TObject obj, TObject obj,
@ -25,9 +25,9 @@ public static class ObjectHelper
TObject obj, TObject obj,
Expression<Func<TObject, TValue>> propertySelector, Expression<Func<TObject, TValue>> propertySelector,
Func<TObject, TValue> valueFactory, Func<TObject, TValue> valueFactory,
params Type[] ignoreAttributeTypes) params Type[]? ignoreAttributeTypes)
{ {
var cacheKey = $"{obj.GetType().FullName}-" + var cacheKey = $"{obj?.GetType().FullName}-" +
$"{propertySelector}-" + $"{propertySelector}-" +
$"{(ignoreAttributeTypes != null ? "-" + string.Join("-", ignoreAttributeTypes.Select(x => x.FullName)) : "")}"; $"{(ignoreAttributeTypes != null ? "-" + string.Join("-", ignoreAttributeTypes.Select(x => x.FullName)) : "")}";
@ -40,7 +40,7 @@ public static class ObjectHelper
var memberExpression = propertySelector.Body.As<MemberExpression>(); var memberExpression = propertySelector.Body.As<MemberExpression>();
var propertyInfo = obj.GetType().GetProperties().FirstOrDefault(x => var propertyInfo = obj?.GetType().GetProperties().FirstOrDefault(x =>
x.Name == memberExpression.Member.Name && x.Name == memberExpression.Member.Name &&
x.GetSetMethod(true) != null); x.GetSetMethod(true) != null);

4
framework/src/Volo.Abp.Core/Volo/Abp/Options/AbpOptionsFactory.cs

@ -9,7 +9,7 @@ public class AbpOptionsFactory<TOptions> : IOptionsFactory<TOptions> where TOpti
{ {
private readonly IEnumerable<IConfigureOptions<TOptions>> _setups; private readonly IEnumerable<IConfigureOptions<TOptions>> _setups;
private readonly IEnumerable<IPostConfigureOptions<TOptions>> _postConfigures; private readonly IEnumerable<IPostConfigureOptions<TOptions>> _postConfigures;
private readonly IEnumerable<IValidateOptions<TOptions>> _validations; private readonly IEnumerable<IValidateOptions<TOptions>>? _validations;
public AbpOptionsFactory( public AbpOptionsFactory(
IEnumerable<IConfigureOptions<TOptions>> setups, IEnumerable<IConfigureOptions<TOptions>> setups,
@ -22,7 +22,7 @@ public class AbpOptionsFactory<TOptions> : IOptionsFactory<TOptions> where TOpti
public AbpOptionsFactory( public AbpOptionsFactory(
IEnumerable<IConfigureOptions<TOptions>> setups, IEnumerable<IConfigureOptions<TOptions>> setups,
IEnumerable<IPostConfigureOptions<TOptions>> postConfigures, IEnumerable<IPostConfigureOptions<TOptions>> postConfigures,
IEnumerable<IValidateOptions<TOptions>> validations) IEnumerable<IValidateOptions<TOptions>>? validations)
{ {
_setups = setups; _setups = setups;
_postConfigures = postConfigures; _postConfigures = postConfigures;

2
framework/src/Volo.Abp.Core/Volo/Abp/Reflection/AssemblyHelper.cs

@ -31,7 +31,7 @@ internal static class AssemblyHelper
} }
catch (ReflectionTypeLoadException ex) catch (ReflectionTypeLoadException ex)
{ {
return ex.Types; return ex.Types!;
} }
} }
} }

18
framework/src/Volo.Abp.Core/Volo/Abp/Reflection/ReflectionHelper.cs

@ -80,7 +80,7 @@ public static class ReflectionHelper
/// <param name="memberInfo">MemberInfo</param> /// <param name="memberInfo">MemberInfo</param>
/// <param name="defaultValue">Default value (null as default)</param> /// <param name="defaultValue">Default value (null as default)</param>
/// <param name="inherit">Inherit attribute from base classes</param> /// <param name="inherit">Inherit attribute from base classes</param>
public static TAttribute GetSingleAttributeOrDefault<TAttribute>(MemberInfo memberInfo, TAttribute defaultValue = default, bool inherit = true) public static TAttribute? GetSingleAttributeOrDefault<TAttribute>(MemberInfo memberInfo, TAttribute? defaultValue = default, bool inherit = true)
where TAttribute : Attribute where TAttribute : Attribute
{ {
//Get attribute on the member //Get attribute on the member
@ -100,7 +100,7 @@ public static class ReflectionHelper
/// <param name="memberInfo">MemberInfo</param> /// <param name="memberInfo">MemberInfo</param>
/// <param name="defaultValue">Default value (null as default)</param> /// <param name="defaultValue">Default value (null as default)</param>
/// <param name="inherit">Inherit attribute from base classes</param> /// <param name="inherit">Inherit attribute from base classes</param>
public static TAttribute GetSingleAttributeOfMemberOrDeclaringTypeOrDefault<TAttribute>(MemberInfo memberInfo, TAttribute defaultValue = default, bool inherit = true) public static TAttribute? GetSingleAttributeOfMemberOrDeclaringTypeOrDefault<TAttribute>(MemberInfo memberInfo, TAttribute? defaultValue = default, bool inherit = true)
where TAttribute : class where TAttribute : class
{ {
return memberInfo.GetCustomAttributes(true).OfType<TAttribute>().FirstOrDefault() return memberInfo.GetCustomAttributes(true).OfType<TAttribute>().FirstOrDefault()
@ -128,7 +128,7 @@ public static class ReflectionHelper
/// <summary> /// <summary>
/// Gets value of a property by it's full path from given object /// Gets value of a property by it's full path from given object
/// </summary> /// </summary>
public static object GetValueByPath(object obj, Type objectType, string propertyPath) public static object? GetValueByPath(object obj, Type objectType, string propertyPath)
{ {
var value = obj; var value = obj;
var currentType = objectType; var currentType = objectType;
@ -167,7 +167,7 @@ public static class ReflectionHelper
{ {
var currentType = objectType; var currentType = objectType;
PropertyInfo property; PropertyInfo property;
var objectPath = currentType.FullName; var objectPath = currentType.FullName!;
var absolutePropertyPath = propertyPath; var absolutePropertyPath = propertyPath;
if (absolutePropertyPath.StartsWith(objectPath)) if (absolutePropertyPath.StartsWith(objectPath))
{ {
@ -178,19 +178,19 @@ public static class ReflectionHelper
if (properties.Length == 1) if (properties.Length == 1)
{ {
property = objectType.GetProperty(properties.First()); property = objectType.GetProperty(properties.First())!;
property.SetValue(obj, value); property.SetValue(obj, value);
return; return;
} }
for (int i = 0; i < properties.Length - 1; i++) for (int i = 0; i < properties.Length - 1; i++)
{ {
property = currentType.GetProperty(properties[i]); property = currentType.GetProperty(properties[i])!;
obj = property.GetValue(obj, null); obj = property.GetValue(obj, null)!;
currentType = property.PropertyType; currentType = property.PropertyType;
} }
property = currentType.GetProperty(properties.Last()); property = currentType.GetProperty(properties.Last())!;
property.SetValue(obj, value); property.SetValue(obj, value);
} }
@ -215,7 +215,7 @@ public static class ReflectionHelper
constants.AddRange(targetType.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy) constants.AddRange(targetType.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
.Where(x => x.IsLiteral && !x.IsInitOnly) .Where(x => x.IsLiteral && !x.IsInitOnly)
.Select(x => x.GetValue(null).ToString())); .Select(x => x.GetValue(null)!.ToString()!));
var nestedTypes = targetType.GetNestedTypes(BindingFlags.Public); var nestedTypes = targetType.GetNestedTypes(BindingFlags.Public);

28
framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs

@ -43,7 +43,7 @@ public static class TypeHelper
return NonNullablePrimitiveTypes.Contains(type); return NonNullablePrimitiveTypes.Contains(type);
} }
public static bool IsFunc(object obj) public static bool IsFunc(object? obj)
{ {
if (obj == null) if (obj == null)
{ {
@ -59,7 +59,7 @@ public static class TypeHelper
return type.GetGenericTypeDefinition() == typeof(Func<>); return type.GetGenericTypeDefinition() == typeof(Func<>);
} }
public static bool IsFunc<TReturn>(object obj) public static bool IsFunc<TReturn>(object? obj)
{ {
return obj != null && obj.GetType() == typeof(Func<TReturn>); return obj != null && obj.GetType() == typeof(Func<TReturn>);
} }
@ -88,13 +88,13 @@ public static class TypeHelper
{ {
if (t.GetGenericArguments().Length > 0 && t.GetGenericTypeDefinition() == typeof(Nullable<>)) if (t.GetGenericArguments().Length > 0 && t.GetGenericTypeDefinition() == typeof(Nullable<>))
{ {
return t.GetGenericArguments().FirstOrDefault(); return t.GetGenericArguments().First();
} }
return t; return t;
} }
public static bool IsEnumerable(Type type, out Type itemType, bool includePrimitives = true) public static bool IsEnumerable(Type type, out Type? itemType, bool includePrimitives = true)
{ {
if (!includePrimitives && IsPrimitiveExtended(type)) if (!includePrimitives && IsPrimitiveExtended(type))
{ {
@ -119,7 +119,7 @@ public static class TypeHelper
return false; return false;
} }
public static bool IsDictionary(Type type, out Type keyType, out Type valueType) public static bool IsDictionary(Type type, out Type? keyType, out Type? valueType)
{ {
var dictionaryTypes = ReflectionHelper var dictionaryTypes = ReflectionHelper
.GetImplementedGenericTypes( .GetImplementedGenericTypes(
@ -167,12 +167,12 @@ public static class TypeHelper
type == typeof(Guid); type == typeof(Guid);
} }
public static T GetDefaultValue<T>() public static T? GetDefaultValue<T>()
{ {
return default; return default;
} }
public static object GetDefaultValue(Type type) public static object? GetDefaultValue(Type type)
{ {
if (type.IsValueType) if (type.IsValueType)
{ {
@ -194,7 +194,8 @@ public static class TypeHelper
if (type.IsGenericType) if (type.IsGenericType)
{ {
var genericType = type.GetGenericTypeDefinition(); var genericType = type.GetGenericTypeDefinition();
return $"{genericType.FullName.Left(genericType.FullName.IndexOf('`'))}<{type.GenericTypeArguments.Select(GetFullNameHandlingNullableAndGenerics).JoinAsString(",")}>"; var genericTypeFullName = genericType.FullName!;
return $"{genericTypeFullName.Left(genericTypeFullName.IndexOf('`'))}<{type.GenericTypeArguments.Select(GetFullNameHandlingNullableAndGenerics).JoinAsString(",")}>";
} }
return type.FullName ?? type.Name; return type.FullName ?? type.Name;
@ -212,7 +213,8 @@ public static class TypeHelper
if (type.IsGenericType) if (type.IsGenericType)
{ {
var genericType = type.GetGenericTypeDefinition(); var genericType = type.GetGenericTypeDefinition();
return $"{genericType.FullName.Left(genericType.FullName.IndexOf('`'))}<{type.GenericTypeArguments.Select(GetSimplifiedName).JoinAsString(",")}>"; var genericTypeFullName = genericType.FullName!;
return $"{genericTypeFullName.Left(genericTypeFullName.IndexOf('`'))}<{type.GenericTypeArguments.Select(GetSimplifiedName).JoinAsString(",")}>";
} }
if (type == typeof(string)) if (type == typeof(string))
@ -303,12 +305,12 @@ public static class TypeHelper
return type.FullName ?? type.Name; return type.FullName ?? type.Name;
} }
public static object ConvertFromString<TTargetType>(string value) public static object? ConvertFromString<TTargetType>(string value)
{ {
return ConvertFromString(typeof(TTargetType), value); return ConvertFromString(typeof(TTargetType), value);
} }
public static object ConvertFromString(Type targetType, string value) public static object? ConvertFromString(Type targetType, string? value)
{ {
if (value == null) if (value == null)
{ {
@ -354,7 +356,7 @@ public static class TypeHelper
{ {
return TypeDescriptor return TypeDescriptor
.GetConverter(targetType) .GetConverter(targetType)
.ConvertFrom(value); .ConvertFrom(value)!;
} }
public static Type StripNullable(Type type) public static Type StripNullable(Type type)
@ -364,7 +366,7 @@ public static class TypeHelper
: type; : type;
} }
public static bool IsDefaultValue([CanBeNull] object obj) public static bool IsDefaultValue(object? obj)
{ {
if (obj == null) if (obj == null)
{ {

2
framework/src/Volo.Abp.Core/Volo/Abp/RemoteServiceAttribute.cs

@ -22,7 +22,7 @@ public class RemoteServiceAttribute : Attribute //TODO: Can we move this to anot
/// Group names of all services of a module expected to be the same. /// Group names of all services of a module expected to be the same.
/// This name is also used to distinguish the service endpoint of this group. /// This name is also used to distinguish the service endpoint of this group.
/// </summary> /// </summary>
public string Name { get; set; } public string Name { get; set; } = default!;
public RemoteServiceAttribute(bool isEnabled = true) public RemoteServiceAttribute(bool isEnabled = true)
{ {

4
framework/src/Volo.Abp.Core/Volo/Abp/SimpleStateChecking/ISimpleStateCheckerSerializer.cs

@ -4,9 +4,9 @@ namespace Volo.Abp.SimpleStateChecking;
public interface ISimpleStateCheckerSerializer public interface ISimpleStateCheckerSerializer
{ {
public string Serialize<TState>(ISimpleStateChecker<TState> checker) public string? Serialize<TState>(ISimpleStateChecker<TState> checker)
where TState : IHasSimpleStateCheckers<TState>; where TState : IHasSimpleStateCheckers<TState>;
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>;
} }

6
framework/src/Volo.Abp.Core/Volo/Abp/SimpleStateChecking/ISimpleStateCheckerSerializerContributor.cs

@ -5,11 +5,9 @@ namespace Volo.Abp.SimpleStateChecking;
public interface ISimpleStateCheckerSerializerContributor public interface ISimpleStateCheckerSerializerContributor
{ {
[CanBeNull] public string? SerializeToJson<TState>(ISimpleStateChecker<TState> checker)
public string SerializeToJson<TState>(ISimpleStateChecker<TState> checker)
where TState : IHasSimpleStateCheckers<TState>; where TState : IHasSimpleStateCheckers<TState>;
[CanBeNull] 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>;
} }

6
framework/src/Volo.Abp.Core/Volo/Abp/SimpleStateChecking/SimpleStateCheckerSerializer.cs

@ -16,8 +16,7 @@ public class SimpleStateCheckerSerializer :
_contributors = contributors; _contributors = contributors;
} }
[CanBeNull] public string? Serialize<TState>(ISimpleStateChecker<TState> checker)
public string Serialize<TState>(ISimpleStateChecker<TState> checker)
where TState : IHasSimpleStateCheckers<TState> where TState : IHasSimpleStateCheckers<TState>
{ {
foreach (var contributor in _contributors) foreach (var contributor in _contributors)
@ -32,8 +31,7 @@ public class SimpleStateCheckerSerializer :
return null; return null;
} }
[CanBeNull] 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>
{ {
foreach (var contributor in _contributors) foreach (var contributor in _contributors)

6
framework/src/Volo.Abp.Core/Volo/Abp/SimpleStateChecking/SimpleStateCheckerSerializerExtensions.cs

@ -7,7 +7,7 @@ namespace Volo.Abp.SimpleStateChecking;
public static class SimpleStateCheckerSerializerExtensions public static class SimpleStateCheckerSerializerExtensions
{ {
public static string Serialize<TState>( public static string? Serialize<TState>(
this ISimpleStateCheckerSerializer serializer, this ISimpleStateCheckerSerializer serializer,
IList<ISimpleStateChecker<TState>> stateCheckers) IList<ISimpleStateChecker<TState>> stateCheckers)
where TState : IHasSimpleStateCheckers<TState> where TState : IHasSimpleStateCheckers<TState>
@ -73,7 +73,7 @@ public static class SimpleStateCheckerSerializerExtensions
return new[] { checker }; return new[] { checker };
} }
var checkers = new List<ISimpleStateChecker<TState>>(); var checkers = new List<ISimpleStateChecker<TState>?>();
for (var i = 0; i < array.Count; i++) for (var i = 0; i < array.Count; i++)
{ {
@ -85,6 +85,6 @@ public static class SimpleStateCheckerSerializerExtensions
checkers.Add(serializer.Deserialize(jsonObject, state)); checkers.Add(serializer.Deserialize(jsonObject, state));
} }
return checkers.Where(x => x != null).ToArray(); return checkers.Where(x => x != null).ToArray()!;
} }
} }

2
framework/src/Volo.Abp.Core/Volo/Abp/Text/Formatting/FormattedStringValueExtracter.cs

@ -68,7 +68,7 @@ public class FormattedStringValueExtracter
Debug.Assert(previousToken != null, "previousToken can not be null since i > 0 here"); Debug.Assert(previousToken != null, "previousToken can not be null since i > 0 here");
result.Matches.Add(new NameValue(previousToken.Text, str.Substring(0, matchIndex))); result.Matches.Add(new NameValue(previousToken!.Text, str.Substring(0, matchIndex)));
str = str.Substring(matchIndex + currentToken.Text.Length); str = str.Substring(matchIndex + currentToken.Text.Length);
} }
} }

2
framework/src/Volo.Abp.Core/Volo/Abp/Text/StringHelper.cs

@ -10,7 +10,7 @@ public class StringHelper
/// <param name="bytes">The byte[] to be converted to string</param> /// <param name="bytes">The byte[] to be converted to string</param>
/// <param name="encoding">The encoding to get string. Default is UTF8</param> /// <param name="encoding">The encoding to get string. Default is UTF8</param>
/// <returns></returns> /// <returns></returns>
public static string ConvertFromBytesWithoutBom(byte[] bytes, Encoding encoding = null) public static string? ConvertFromBytesWithoutBom(byte[]? bytes, Encoding? encoding = null)
{ {
if (bytes == null) if (bytes == null)
{ {

40
framework/src/Volo.Abp.Core/Volo/Abp/Threading/InternalAsyncHelper.cs

@ -9,9 +9,9 @@ namespace Volo.Abp.Threading;
//TODO: Cache GetMethod reflection! //TODO: Cache GetMethod reflection!
public static class InternalAsyncHelper public static class InternalAsyncHelper
{ {
public static async Task AwaitTaskWithFinally(Task actualReturnValue, Action<Exception> finalAction) public static async Task AwaitTaskWithFinally(Task actualReturnValue, Action<Exception?> finalAction)
{ {
Exception exception = null; Exception? exception = null;
try try
{ {
@ -28,9 +28,9 @@ public static class InternalAsyncHelper
} }
} }
public static async Task AwaitTaskWithPostActionAndFinally(Task actualReturnValue, Func<Task> postAction, Action<Exception> finalAction) public static async Task AwaitTaskWithPostActionAndFinally(Task actualReturnValue, Func<Task> postAction, Action<Exception?> finalAction)
{ {
Exception exception = null; Exception? exception = null;
try try
{ {
@ -48,9 +48,9 @@ public static class InternalAsyncHelper
} }
} }
public static async Task AwaitTaskWithPreActionAndPostActionAndFinally(Func<Task> actualReturnValue, Func<Task> preAction = null, Func<Task> postAction = null, Action<Exception> finalAction = null) public static async Task AwaitTaskWithPreActionAndPostActionAndFinally(Func<Task> actualReturnValue, Func<Task>? preAction = null, Func<Task>? postAction = null, Action<Exception?>? finalAction = null)
{ {
Exception exception = null; Exception? exception = null;
try try
{ {
@ -80,9 +80,9 @@ public static class InternalAsyncHelper
} }
} }
public static async Task<T> AwaitTaskWithFinallyAndGetResult<T>(Task<T> actualReturnValue, Action<Exception> finalAction) public static async Task<T> AwaitTaskWithFinallyAndGetResult<T>(Task<T> actualReturnValue, Action<Exception?> finalAction)
{ {
Exception exception = null; Exception? exception = null;
try try
{ {
@ -103,14 +103,14 @@ public static class InternalAsyncHelper
{ {
return typeof(InternalAsyncHelper) return typeof(InternalAsyncHelper)
.GetTypeInfo() .GetTypeInfo()
.GetMethod("AwaitTaskWithFinallyAndGetResult", BindingFlags.Public | BindingFlags.Static) .GetMethod("AwaitTaskWithFinallyAndGetResult", BindingFlags.Public | BindingFlags.Static)!
.MakeGenericMethod(taskReturnType) .MakeGenericMethod(taskReturnType)
.Invoke(null, new object[] { actualReturnValue, finalAction }); .Invoke(null, new object[] { actualReturnValue, finalAction })!;
} }
public static async Task<T> AwaitTaskWithPostActionAndFinallyAndGetResult<T>(Task<T> actualReturnValue, Func<Task> postAction, Action<Exception> finalAction) public static async Task<T> AwaitTaskWithPostActionAndFinallyAndGetResult<T>(Task<T> actualReturnValue, Func<Task> postAction, Action<Exception?> finalAction)
{ {
Exception exception = null; Exception? exception = null;
try try
{ {
@ -133,14 +133,14 @@ public static class InternalAsyncHelper
{ {
return typeof(InternalAsyncHelper) return typeof(InternalAsyncHelper)
.GetTypeInfo() .GetTypeInfo()
.GetMethod("AwaitTaskWithPostActionAndFinallyAndGetResult", BindingFlags.Public | BindingFlags.Static) .GetMethod("AwaitTaskWithPostActionAndFinallyAndGetResult", BindingFlags.Public | BindingFlags.Static)!
.MakeGenericMethod(taskReturnType) .MakeGenericMethod(taskReturnType)
.Invoke(null, new object[] { actualReturnValue, action, finalAction }); .Invoke(null, new object[] { actualReturnValue, action, finalAction })!;
} }
public static async Task<T> AwaitTaskWithPreActionAndPostActionAndFinallyAndGetResult<T>(Func<Task<T>> actualReturnValue, Func<Task> preAction = null, Func<Task> postAction = null, Action<Exception> finalAction = null) public static async Task<T> AwaitTaskWithPreActionAndPostActionAndFinallyAndGetResult<T>(Func<Task<T>> actualReturnValue, Func<Task>? preAction = null, Func<Task>? postAction = null, Action<Exception?>? finalAction = null)
{ {
Exception exception = null; Exception? exception = null;
try try
{ {
@ -169,19 +169,19 @@ public static class InternalAsyncHelper
} }
} }
public static object CallAwaitTaskWithPreActionAndPostActionAndFinallyAndGetResult(Type taskReturnType, Func<object> actualReturnValue, Func<Task> preAction = null, Func<Task> postAction = null, Action<Exception> finalAction = null) public static object CallAwaitTaskWithPreActionAndPostActionAndFinallyAndGetResult(Type taskReturnType, Func<object> actualReturnValue, Func<Task>? preAction = null, Func<Task>? postAction = null, Action<Exception>? finalAction = null)
{ {
var returnFunc = typeof(InternalAsyncHelper) var returnFunc = typeof(InternalAsyncHelper)
.GetTypeInfo() .GetTypeInfo()
.GetMethod("ConvertFuncOfObjectToFuncOfTask", BindingFlags.NonPublic | BindingFlags.Static) .GetMethod("ConvertFuncOfObjectToFuncOfTask", BindingFlags.NonPublic | BindingFlags.Static)!
.MakeGenericMethod(taskReturnType) .MakeGenericMethod(taskReturnType)
.Invoke(null, new object[] { actualReturnValue }); .Invoke(null, new object[] { actualReturnValue });
return typeof(InternalAsyncHelper) return typeof(InternalAsyncHelper)
.GetTypeInfo() .GetTypeInfo()
.GetMethod("AwaitTaskWithPreActionAndPostActionAndFinallyAndGetResult", BindingFlags.Public | BindingFlags.Static) .GetMethod("AwaitTaskWithPreActionAndPostActionAndFinallyAndGetResult", BindingFlags.Public | BindingFlags.Static)!
.MakeGenericMethod(taskReturnType) .MakeGenericMethod(taskReturnType)
.Invoke(null, new object[] { returnFunc, preAction, postAction, finalAction }); .Invoke(null, new object?[] { returnFunc, preAction, postAction, finalAction })!;
} }
[UsedImplicitly] [UsedImplicitly]

6
framework/src/Volo.Abp.Core/Volo/Abp/UserFriendlyException.cs

@ -12,9 +12,9 @@ public class UserFriendlyException : BusinessException, IUserFriendlyException
{ {
public UserFriendlyException( public UserFriendlyException(
string message, string message,
string code = null, string? code = null,
string details = null, string? details = null,
Exception innerException = null, Exception? innerException = null,
LogLevel logLevel = LogLevel.Warning) LogLevel logLevel = LogLevel.Warning)
: base( : base(
code, code,

6
framework/src/Volo.Abp.Core/Volo/Abp/Validation/DynamicMaxLengthAttribute.cs

@ -8,7 +8,7 @@ namespace Volo.Abp.Validation;
public class DynamicMaxLengthAttribute : MaxLengthAttribute public class DynamicMaxLengthAttribute : MaxLengthAttribute
{ {
private static readonly FieldInfo MaximumLengthField; private static readonly FieldInfo? MaximumLengthField;
static DynamicMaxLengthAttribute() static DynamicMaxLengthAttribute()
{ {
@ -21,7 +21,7 @@ public class DynamicMaxLengthAttribute : MaxLengthAttribute
public DynamicMaxLengthAttribute( public DynamicMaxLengthAttribute(
[NotNull] Type sourceType, [NotNull] Type sourceType,
[CanBeNull] string maximumLengthPropertyName) string? maximumLengthPropertyName)
{ {
Check.NotNull(sourceType, nameof(sourceType)); Check.NotNull(sourceType, nameof(sourceType));
@ -32,7 +32,7 @@ public class DynamicMaxLengthAttribute : MaxLengthAttribute
BindingFlags.Static | BindingFlags.Public BindingFlags.Static | BindingFlags.Public
); );
Debug.Assert(maximumLengthProperty != null, nameof(maximumLengthProperty) + " != null"); Debug.Assert(maximumLengthProperty != null, nameof(maximumLengthProperty) + " != null");
MaximumLengthField.SetValue(this, (int)maximumLengthProperty.GetValue(null)); MaximumLengthField?.SetValue(this, (int)maximumLengthProperty?.GetValue(null)!);
} }
} }
} }

12
framework/src/Volo.Abp.Core/Volo/Abp/Validation/DynamicRangeAttribute.cs

@ -8,8 +8,8 @@ namespace Volo.Abp.Validation;
public class DynamicRangeAttribute : RangeAttribute public class DynamicRangeAttribute : RangeAttribute
{ {
private static readonly FieldInfo MaximumField; private static readonly FieldInfo? MaximumField;
private static readonly FieldInfo MinimumField; private static readonly FieldInfo? MinimumField;
static DynamicRangeAttribute() static DynamicRangeAttribute()
{ {
@ -33,8 +33,8 @@ public class DynamicRangeAttribute : RangeAttribute
public DynamicRangeAttribute( public DynamicRangeAttribute(
[NotNull] Type sourceType, [NotNull] Type sourceType,
[NotNull] Type operandType, [NotNull] Type operandType,
[CanBeNull] string minimumPropertyName, string? minimumPropertyName,
[CanBeNull] string maximumPropertyName string? maximumPropertyName
) )
: base(operandType, string.Empty, string.Empty) : base(operandType, string.Empty, string.Empty)
{ {
@ -47,7 +47,7 @@ public class DynamicRangeAttribute : RangeAttribute
BindingFlags.Static | BindingFlags.Public BindingFlags.Static | BindingFlags.Public
); );
Debug.Assert(minimumProperty != null, nameof(minimumProperty) + " != null"); Debug.Assert(minimumProperty != null, nameof(minimumProperty) + " != null");
MinimumField.SetValue(this, minimumProperty.GetValue(null)); MinimumField?.SetValue(this, minimumProperty?.GetValue(null));
} }
if (maximumPropertyName != null) if (maximumPropertyName != null)
@ -57,7 +57,7 @@ public class DynamicRangeAttribute : RangeAttribute
BindingFlags.Static | BindingFlags.Public BindingFlags.Static | BindingFlags.Public
); );
Debug.Assert(maximumProperty != null, nameof(maximumProperty) + " != null"); Debug.Assert(maximumProperty != null, nameof(maximumProperty) + " != null");
MaximumField.SetValue(this, maximumProperty.GetValue(null)); MaximumField?.SetValue(this, maximumProperty?.GetValue(null));
} }
} }
} }

10
framework/src/Volo.Abp.Core/Volo/Abp/Validation/DynamicStringLengthAttribute.cs

@ -12,7 +12,7 @@ namespace Volo.Abp.Validation;
/// </summary> /// </summary>
public class DynamicStringLengthAttribute : StringLengthAttribute public class DynamicStringLengthAttribute : StringLengthAttribute
{ {
private static readonly FieldInfo MaximumLengthField; private static readonly FieldInfo? MaximumLengthField;
static DynamicStringLengthAttribute() static DynamicStringLengthAttribute()
{ {
@ -28,8 +28,8 @@ public class DynamicStringLengthAttribute : StringLengthAttribute
/// <param name="minimumLengthPropertyName">The name of the public static property for the <see cref="StringLengthAttribute.MinimumLength"/></param> /// <param name="minimumLengthPropertyName">The name of the public static property for the <see cref="StringLengthAttribute.MinimumLength"/></param>
public DynamicStringLengthAttribute( public DynamicStringLengthAttribute(
[NotNull] Type sourceType, [NotNull] Type sourceType,
[CanBeNull] string maximumLengthPropertyName, string? maximumLengthPropertyName,
[CanBeNull] string minimumLengthPropertyName = null) string? minimumLengthPropertyName = null)
: base(0) : base(0)
{ {
Check.NotNull(sourceType, nameof(sourceType)); Check.NotNull(sourceType, nameof(sourceType));
@ -41,7 +41,7 @@ public class DynamicStringLengthAttribute : StringLengthAttribute
BindingFlags.Static | BindingFlags.Public BindingFlags.Static | BindingFlags.Public
); );
Debug.Assert(maximumLengthProperty != null, nameof(maximumLengthProperty) + " != null"); Debug.Assert(maximumLengthProperty != null, nameof(maximumLengthProperty) + " != null");
MaximumLengthField.SetValue(this, (int)maximumLengthProperty.GetValue(null)); MaximumLengthField?.SetValue(this, (int)maximumLengthProperty?.GetValue(null)!);
} }
if (minimumLengthPropertyName != null) if (minimumLengthPropertyName != null)
@ -51,7 +51,7 @@ public class DynamicStringLengthAttribute : StringLengthAttribute
BindingFlags.Static | BindingFlags.Public BindingFlags.Static | BindingFlags.Public
); );
Debug.Assert(minimumLengthProperty != null, nameof(minimumLengthProperty) + " != null"); Debug.Assert(minimumLengthProperty != null, nameof(minimumLengthProperty) + " != null");
MinimumLength = (int)minimumLengthProperty.GetValue(null); MinimumLength = (int)minimumLengthProperty?.GetValue(null)!;
} }
} }
} }

Loading…
Cancel
Save