Skip to content

Commit

Permalink
Merge pull request #17020 from abpframework/liangshiwei/group1
Browse files Browse the repository at this point in the history
Group1 Enable nullable annotations
  • Loading branch information
maliming authored Jul 5, 2023
2 parents fe5a51c + b598e84 commit 2c41001
Show file tree
Hide file tree
Showing 243 changed files with 852 additions and 807 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.ApiVersioning.Abstractions</AssemblyName>
<PackageId>Volo.Abp.ApiVersioning.Abstractions</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface IRequestedApiVersion
{
string Current { get; }
string? Current { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class NullRequestedApiVersion : IRequestedApiVersion
{
public static NullRequestedApiVersion Instance = new NullRequestedApiVersion();

public string Current => null;
public string? Current => null;

private NullRequestedApiVersion()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class AbpWebAssemblyApplicationCreationOptionsAutofacExtensions
{
public static void UseAutofac(
[NotNull] this AbpWebAssemblyApplicationCreationOptions options,
[CanBeNull] Action<ContainerBuilder> configure = null)
Action<ContainerBuilder>? configure = null)
{
options.HostBuilder.Services.AddAutofacServiceProviderFactory();
options.HostBuilder.ConfigureContainer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<RootNamespace />
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void Populate(
public static void Populate(
this ContainerBuilder builder,
IServiceCollection services,
object lifetimeScopeTagForSingletons)
object? lifetimeScopeTagForSingletons)
{
if (services == null)
{
Expand Down Expand Up @@ -134,7 +134,7 @@ public static void Populate(
private static IRegistrationBuilder<object, TActivatorData, TRegistrationStyle> ConfigureLifecycle<TActivatorData, TRegistrationStyle>(
this IRegistrationBuilder<object, TActivatorData, TRegistrationStyle> registrationBuilder,
ServiceLifetime lifecycleKind,
object lifetimeScopeTagForSingleton)
object? lifetimeScopeTagForSingleton)
{
switch (lifecycleKind)
{
Expand Down Expand Up @@ -179,7 +179,7 @@ private static IRegistrationBuilder<object, TActivatorData, TRegistrationStyle>
private static void Register(
ContainerBuilder builder,
IServiceCollection services,
object lifetimeScopeTagForSingletons)
object? lifetimeScopeTagForSingletons)
{
var moduleContainer = services.GetSingletonInstance<IModuleContainer>();
var registrationActionList = services.GetRegistrationActionList();
Expand Down Expand Up @@ -223,7 +223,7 @@ private static void Register(
else
{
builder
.RegisterInstance(descriptor.ImplementationInstance)
.RegisterInstance(descriptor.ImplementationInstance!)
.As(descriptor.ServiceType)
.ConfigureLifecycle(descriptor.Lifetime, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static ContainerBuilder GetContainerBuilder([NotNull] this IServiceCollec
return builder;
}

public static IServiceProvider BuildAutofacServiceProvider([NotNull] this IServiceCollection services, Action<ContainerBuilder> builderAction = null)
public static IServiceProvider BuildAutofacServiceProvider([NotNull] this IServiceCollection services, Action<ContainerBuilder>? builderAction = null)
{
return services.BuildServiceProviderFromFactory(builderAction);
}
Expand Down
2 changes: 2 additions & 0 deletions framework/src/Volo.Abp.Autofac/Volo.Abp.Autofac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.Autofac</AssemblyName>
<PackageId>Volo.Abp.Autofac</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Volo.Abp.Autofac;
public class AbpAutofacServiceProviderFactory : IServiceProviderFactory<ContainerBuilder>
{
private readonly ContainerBuilder _builder;
private IServiceCollection _services;
private IServiceCollection _services = default!;

public AbpAutofacServiceProviderFactory(ContainerBuilder builder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.Castle.Core</AssemblyName>
<PackageId>Volo.Abp.Castle.Core</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class CastleAbpMethodInvocationAdapterBase : IAbpMethodInvocatio

public MethodInfo Method => Invocation.MethodInvocationTarget ?? Invocation.Method;

public object ReturnValue { get; set; }
public object ReturnValue { get; set; } = default!;

protected IInvocation Invocation { get; }

Expand All @@ -39,7 +39,7 @@ private IReadOnlyDictionary<string, object> GetArgumentsDictionary()
var methodParameters = Method.GetParameters();
for (int i = 0; i < methodParameters.Length; i++)
{
dict[methodParameters[i].Name] = Invocation.Arguments[i];
dict[methodParameters[i].Name!] = Invocation.Arguments[i];
}

return dict;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public CastleAbpMethodInvocationAdapterWithReturnValue(IInvocation invocation,

public override async Task ProceedAsync()
{
ReturnValue = await Proceed(Invocation, ProceedInfo);
ReturnValue = (await Proceed(Invocation, ProceedInfo))!;
}
}
4 changes: 2 additions & 2 deletions framework/src/Volo.Abp.Core/Volo/Abp/AbpException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public AbpException()

}

public AbpException(string message)
public AbpException(string? message)
: base(message)
{

}

public AbpException(string message, Exception innerException)
public AbpException(string? message, Exception? innerException)
: base(message, innerException)
{

Expand Down
2 changes: 2 additions & 0 deletions framework/src/Volo.Abp.Data/Volo.Abp.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.Data</AssemblyName>
<PackageId>Volo.Abp.Data</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public static class AbpCommonDbProperties
/// <summary>
/// Default value: null.
/// </summary>
public static string DbSchema { get; set; } = null;
public static string? DbSchema { get; set; } = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ namespace Volo.Abp.Data;

public static class AbpDataMigrationEnvironmentExtensions
{
public static void AddDataMigrationEnvironment(this AbpApplicationCreationOptions options, AbpDataMigrationEnvironment environment = null)
public static void AddDataMigrationEnvironment(this AbpApplicationCreationOptions options, AbpDataMigrationEnvironment? environment = null)
{
options.Services.AddDataMigrationEnvironment(environment ?? new AbpDataMigrationEnvironment());
}

public static void AddDataMigrationEnvironment(this IServiceCollection services, AbpDataMigrationEnvironment environment = null)
public static void AddDataMigrationEnvironment(this IServiceCollection services, AbpDataMigrationEnvironment? environment = null)
{
services.AddObjectAccessor<AbpDataMigrationEnvironment>(environment ?? new AbpDataMigrationEnvironment());
}

public static AbpDataMigrationEnvironment GetDataMigrationEnvironment(this IServiceCollection services)
public static AbpDataMigrationEnvironment? GetDataMigrationEnvironment(this IServiceCollection services)
{
return services.GetObjectOrNull<AbpDataMigrationEnvironment>();
}
Expand All @@ -26,7 +26,7 @@ public static bool IsDataMigrationEnvironment(this IServiceCollection services)
return services.GetDataMigrationEnvironment() != null;
}

public static AbpDataMigrationEnvironment GetDataMigrationEnvironment(this IServiceProvider serviceProvider)
public static AbpDataMigrationEnvironment? GetDataMigrationEnvironment(this IServiceProvider serviceProvider)
{
return serviceProvider.GetService<IObjectAccessor<AbpDataMigrationEnvironment>>()?.Value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public AbpDatabaseInfoDictionary()
ConnectionIndex = new Dictionary<string, AbpDatabaseInfo>();
}

[CanBeNull]
public AbpDatabaseInfo GetMappedDatabaseOrNull(string connectionStringName)
public AbpDatabaseInfo? GetMappedDatabaseOrNull(string connectionStringName)
{
return ConnectionIndex.GetOrDefault(connectionStringName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public AbpDbConnectionOptions()
Databases = new AbpDatabaseInfoDictionary();
}

public string GetConnectionStringOrNull(
public string? GetConnectionStringOrNull(
string connectionStringName,
bool fallbackToDatabaseMappings = true,
bool fallbackToDefault = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace Volo.Abp.Data;
[EventName("abp.data.applied_database_migrations")]
public class AppliedDatabaseMigrationsEto
{
public string DatabaseName { get; set; }
public string DatabaseName { get; set; } = default!;
public Guid? TenantId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public class ApplyDatabaseMigrationsEto : EtoBase
{
public Guid? TenantId { get; set; }

public string DatabaseName { get; set; }
public string DatabaseName { get; set; } = default!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace Volo.Abp.Data;

public static class ConcurrencyStampExtensions
{
public static void SetConcurrencyStampIfNotNull(this IHasConcurrencyStamp entity, [CanBeNull] string concurrencyStamp)
public static void SetConcurrencyStampIfNotNull(this IHasConcurrencyStamp entity, string? concurrencyStamp)
{
if (!concurrencyStamp.IsNullOrEmpty())
{
entity.ConcurrencyStamp = concurrencyStamp;
entity.ConcurrencyStamp = concurrencyStamp!;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static string GetConnStringName(Type type)

if (nameAttribute == null)
{
return type.FullName;
return type.FullName!;
}

return nameAttribute.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
namespace Volo.Abp.Data;

[Serializable]
public class ConnectionStrings : Dictionary<string, string>
public class ConnectionStrings : Dictionary<string, string?>
{
public const string DefaultConnectionStringName = "Default";

public string Default {
public string? Default {
get => this.GetOrDefault(DefaultConnectionStringName);
set => this[DefaultConnectionStringName] = value;
}
Expand Down
12 changes: 6 additions & 6 deletions framework/src/Volo.Abp.Data/Volo/Abp/Data/DataFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public bool IsEnabled<TFilter>()
private IDataFilter<TFilter> GetFilter<TFilter>()
where TFilter : class
{
return _filters.GetOrAdd(
return (_filters.GetOrAdd(
typeof(TFilter),
factory: () => _serviceProvider.GetRequiredService<IDataFilter<TFilter>>()
) as IDataFilter<TFilter>;
factory: () => _serviceProvider.GetRequiredService<IDataFilter<TFilter>>()
) as IDataFilter<TFilter>)!;
}
}

Expand All @@ -55,7 +55,7 @@ public class DataFilter<TFilter> : IDataFilter<TFilter>
public bool IsEnabled {
get {
EnsureInitialized();
return _filter.Value.IsEnabled;
return _filter.Value!.IsEnabled;
}
}

Expand All @@ -76,7 +76,7 @@ public IDisposable Enable()
return NullDisposable.Instance;
}

_filter.Value.IsEnabled = true;
_filter.Value!.IsEnabled = true;

return new DisposeAction(() => Disable());
}
Expand All @@ -88,7 +88,7 @@ public IDisposable Disable()
return NullDisposable.Instance;
}

_filter.Value.IsEnabled = false;
_filter.Value!.IsEnabled = false;

return new DisposeAction(() => Enable());
}
Expand Down
9 changes: 4 additions & 5 deletions framework/src/Volo.Abp.Data/Volo/Abp/Data/DataSeedContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class DataSeedContext
/// Returns the value in the <see cref="Properties"/> dictionary by given <paramref name="name"/>.
/// Returns null if given <paramref name="name"/> is not present in the <see cref="Properties"/> dictionary.
/// </returns>
[CanBeNull]
public object this[string name] {
public object? this[string name] {
get => Properties.GetOrDefault(name);
set => Properties[name] = value;
}
Expand All @@ -26,19 +25,19 @@ public object this[string name] {
/// Can be used to get/set custom properties.
/// </summary>
[NotNull]
public Dictionary<string, object> Properties { get; }
public Dictionary<string, object?> Properties { get; }

public DataSeedContext(Guid? tenantId = null)
{
TenantId = tenantId;
Properties = new Dictionary<string, object>();
Properties = new Dictionary<string, object?>();
}

/// <summary>
/// Sets a property in the <see cref="Properties"/> dictionary.
/// This is a shortcut for nested calls on this object.
/// </summary>
public virtual DataSeedContext WithProperty(string key, object value)
public virtual DataSeedContext WithProperty(string key, object? value)
{
Properties[key] = value;
return this;
Expand Down
4 changes: 2 additions & 2 deletions framework/src/Volo.Abp.Data/Volo/Abp/Data/DataSeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public virtual async Task SeedAsync(DataSeedContext context)
foreach (var contributorType in Options.Contributors)
{
var options = context.Properties.TryGetValue(DataSeederExtensions.SeedInSeparateUowOptions, out var uowOptions)
? (AbpUnitOfWorkOptions) uowOptions
? (AbpUnitOfWorkOptions) uowOptions!
: new AbpUnitOfWorkOptions();
var requiresNew = context.Properties.TryGetValue(DataSeederExtensions.SeedInSeparateUowRequiresNew, out var obj) && (bool) obj;
var requiresNew = context.Properties.TryGetValue(DataSeederExtensions.SeedInSeparateUowRequiresNew, out var obj) && (bool) obj!;

using (var uow = manager.Begin(options, requiresNew))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static Task SeedAsync(this IDataSeeder seeder, Guid? tenantId = null)
return seeder.SeedAsync(new DataSeedContext(tenantId));
}

public static Task SeedInSeparateUowAsync(this IDataSeeder seeder, Guid? tenantId = null, AbpUnitOfWorkOptions options = null, bool requiresNew = false)
public static Task SeedInSeparateUowAsync(this IDataSeeder seeder, Guid? tenantId = null, AbpUnitOfWorkOptions? options = null, bool requiresNew = false)
{
var context = new DataSeedContext(tenantId);
context.WithProperty(SeedInSeparateUow, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public DefaultConnectionStringResolver(
}

[Obsolete("Use ResolveAsync method.")]
public virtual string Resolve(string connectionStringName = null)
public virtual string Resolve(string? connectionStringName = null)
{
return ResolveInternal(connectionStringName);
return ResolveInternal(connectionStringName)!;
}

public virtual Task<string> ResolveAsync(string connectionStringName = null)
public virtual Task<string> ResolveAsync(string? connectionStringName = null)
{
return Task.FromResult(ResolveInternal(connectionStringName));
return Task.FromResult(ResolveInternal(connectionStringName))!;
}

private string ResolveInternal(string connectionStringName)
private string? ResolveInternal(string? connectionStringName)
{
if (connectionStringName == null)
{
Expand Down
Loading

0 comments on commit 2c41001

Please sign in to comment.