Skip to content

Commit

Permalink
Update for nullable reference type
Browse files Browse the repository at this point in the history
  • Loading branch information
usausa committed Feb 8, 2021
1 parent b3198cd commit d3f3aa0
Show file tree
Hide file tree
Showing 39 changed files with 206 additions and 180 deletions.
2 changes: 1 addition & 1 deletion Example.GenericHost/Example.GenericHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta1" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta2" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Example.GenericHost/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace Example.GenericHost
{
public class Settings
{
public string Data { get; set; }
public string? Data { get; set; }
}
}
2 changes: 1 addition & 1 deletion Example.WebApplication/Example.WebApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.1" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta1" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta2" />
<PackageReference Include="Usa.Smart.Data" Version="2.0.0-beta1" />
<PackageReference Include="Usa.Smart.Data.Mapper" Version="2.0.0-beta1" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Example.WebApplication/Models/CharacterEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class CharacterEntity
{
public int Id { get; set; }

public string Name { get; set; }
public string? Name { get; set; }

public int Level { get; set; }
}
Expand Down
8 changes: 5 additions & 3 deletions Example.WebApplication/Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace Example.WebApplication.Models
{
using System;

public class ErrorViewModel
{
public string RequestId { get; set; }
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
public bool ShowRequestId => !String.IsNullOrEmpty(RequestId);
}
}
}
2 changes: 1 addition & 1 deletion Example.WebApplication/Models/ItemEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class ItemEntity
{
public int Id { get; set; }

public string Name { get; set; }
public string? Name { get; set; }

public int Price { get; set; }
}
Expand Down
3 changes: 3 additions & 0 deletions Example.WebApplication/Settings/ProfileSettings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace Example.WebApplication.Settings
{
using System.Diagnostics.CodeAnalysis;

public class ProfileSettings
{
[AllowNull]
public string[] Genders { get; set; }
}
}
14 changes: 8 additions & 6 deletions Smart.Resolver.Benchmark/Benchmarks/SmartDefaultBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Smart.Resolver.Benchmark.Benchmarks
{
using System;
using System.Collections.Generic;

using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;

using Microsoft.Extensions.DependencyInjection;
Expand All @@ -13,8 +13,10 @@ namespace Smart.Resolver.Benchmark.Benchmarks
[Config(typeof(BenchmarkConfig))]
public class SmartDefaultBenchmark
{
[AllowNull]
private SmartResolver resolver;

[AllowNull]
private IServiceProvider provider;

[GlobalSetup]
Expand Down Expand Up @@ -141,31 +143,31 @@ public void MultipleTransient()
[Benchmark(OperationsPerInvoke = 5)]
public void AspNet()
{
var factory = (IServiceScopeFactory)provider.GetService(typeof(IServiceScopeFactory));
var factory = (IServiceScopeFactory)provider.GetService(typeof(IServiceScopeFactory))!;
using (var scope = factory.CreateScope())
{
scope.ServiceProvider.GetService(typeof(Controller));
}

factory = (IServiceScopeFactory)provider.GetService(typeof(IServiceScopeFactory));
factory = (IServiceScopeFactory)provider.GetService(typeof(IServiceScopeFactory))!;
using (var scope = factory.CreateScope())
{
scope.ServiceProvider.GetService(typeof(Controller));
}

factory = (IServiceScopeFactory)provider.GetService(typeof(IServiceScopeFactory));
factory = (IServiceScopeFactory)provider.GetService(typeof(IServiceScopeFactory))!;
using (var scope = factory.CreateScope())
{
scope.ServiceProvider.GetService(typeof(Controller));
}

factory = (IServiceScopeFactory)provider.GetService(typeof(IServiceScopeFactory));
factory = (IServiceScopeFactory)provider.GetService(typeof(IServiceScopeFactory))!;
using (var scope = factory.CreateScope())
{
scope.ServiceProvider.GetService(typeof(Controller));
}

factory = (IServiceScopeFactory)provider.GetService(typeof(IServiceScopeFactory));
factory = (IServiceScopeFactory)provider.GetService(typeof(IServiceScopeFactory))!;
using (var scope = factory.CreateScope())
{
scope.ServiceProvider.GetService(typeof(Controller));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Smart.Resolver.Benchmark.Benchmarks
{
using System.Collections.Generic;

using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;

using Smart.Reflection;
Expand All @@ -11,6 +11,7 @@ namespace Smart.Resolver.Benchmark.Benchmarks
[Config(typeof(BenchmarkConfig))]
public class SmartUseReflectionBenchmark
{
[AllowNull]
private SmartResolver resolver;

[GlobalSetup]
Expand Down
4 changes: 2 additions & 2 deletions Smart.Resolver.Benchmark/Classes/Generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ namespace Smart.Resolver.Benchmark.Classes
{
public interface IGenericObject<T>
{
T Value { get; set; }
T? Value { get; set; }
}

public class GenericObject<T> : IGenericObject<T>
{
public T Value { get; set; }
public T? Value { get; set; }
}
}
2 changes: 1 addition & 1 deletion Smart.Resolver.Benchmark/Smart.Resolver.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta1" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta1" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta1" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta2" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 0 additions & 25 deletions Smart.Resolver.Tests/Resolver/ConstraintTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,6 @@ public bool Match(BindingMetadata metadata)
{
return metadata.Has(Key);
}

public bool Equals(IConstraint other)
{
return other is HasMetadataConstraint constraint && String.Equals(Key, constraint.Key, StringComparison.Ordinal);
}

public override bool Equals(object obj)
{
if (obj is null)
{
return false;
}

if (ReferenceEquals(this, obj))
{
return true;
}

return obj is NameConstraint constraint && Equals(constraint);
}

public override int GetHashCode()
{
return Key?.GetHashCode(StringComparison.Ordinal) ?? 0;
}
}

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = true)]
Expand Down
2 changes: 1 addition & 1 deletion Smart.Resolver.Tests/Resolver/Mocks/HasPropertyObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace Smart.Resolver.Mocks
public class HasPropertyObject
{
[Inject]
public SimpleObject Injected { get; set; }
public SimpleObject? Injected { get; set; }
}
}
2 changes: 1 addition & 1 deletion Smart.Resolver.Tests/Resolver/ProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public sealed class CustomInitializeProcessor : IProcessor

public int Order { get; } = 1;

public Action<IResolver, object> CreateProcessor(Type type)
public Action<IResolver, object>? CreateProcessor(Type type)
{
if (!CustomInitializableType.IsAssignableFrom(type))
{
Expand Down
2 changes: 1 addition & 1 deletion Smart.Resolver.Tests/Resolver/ProviderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public class MultiConstructorObject

public SimpleObject SimpleObject { get; }

public IService Service { get; }
public IService? Service { get; }

public MultiConstructorObject(SimpleObject simpleObject)
{
Expand Down
8 changes: 4 additions & 4 deletions Smart.Resolver.Tests/Resolver/ResolverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace Smart.Resolver
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

using Smart.ComponentModel;
Expand Down Expand Up @@ -41,15 +42,14 @@ public void ObjectBindingCreatedByOpenGenericMissingResolver()

public interface IGenericService<out T>
{
[return: MaybeNull]
T Create();
}

public class GenericService<T> : IGenericService<T>
{
public T Create()
{
return default;
}
[return: MaybeNull]
public T Create() => default;
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions Smart.Resolver.Tests/Resolver/ScopeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ public Func<IResolver, object> Create(Func<object> factory)
{
return _ =>
{
if (Cache.Value.TryGetValue(this, out var value))
if (Cache.Value!.TryGetValue(this, out var value))
{
return value;
}

value = factory();
Cache.Value[this] = value;
Cache.Value![this] = value;

return value;
};
Expand Down
2 changes: 1 addition & 1 deletion Smart.Resolver.Tests/Smart.Resolver.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta1" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public BindingContextInitializeProcessor(int order)
Order = order;
}

public Action<IResolver, object> CreateProcessor(Type type)
public Action<IResolver, object>? CreateProcessor(Type type)
{
if (!BindableObjectType.IsAssignableFrom(type))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public BindingContextInjectProcessor(int order)
Order = order;
}

public Action<IResolver, object> CreateProcessor(Type type)
public Action<IResolver, object>? CreateProcessor(Type type)
{
if (!BindableObjectType.IsAssignableFrom(type))
{
Expand Down
2 changes: 1 addition & 1 deletion Smart.Resolver.Xamarin/Smart.Resolver.Xamarin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta1" />
<PackageReference Include="Usa.Smart.Core" Version="2.0.0-beta2" />
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1821">
<NoWarn>NU1701</NoWarn>
</PackageReference>
Expand Down
9 changes: 2 additions & 7 deletions Smart.Resolver/Resolver/Bindings/Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class Binding

public Type Type { get; }

public IProvider? Provider { get; }
public IProvider Provider { get; }

public IScope? Scope { get; }

Expand All @@ -24,17 +24,12 @@ public sealed class Binding

public ParameterMap PropertyValues { get; }

public Binding(Type type)
: this(type, null, null, null, null, null)
{
}

public Binding(Type type, IProvider provider)
: this(type, provider, null, null, null, null)
{
}

public Binding(Type type, IProvider? provider, IScope? scope, BindingMetadata? metadata, ParameterMap? constructorArguments, ParameterMap? propertyValues)
public Binding(Type type, IProvider provider, IScope? scope, BindingMetadata? metadata, ParameterMap? constructorArguments, ParameterMap? propertyValues)
{
Type = type;
Provider = provider;
Expand Down
4 changes: 2 additions & 2 deletions Smart.Resolver/Resolver/Builders/EmitFactoryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class EmitFactoryBuilder : IFactoryBuilder
private static readonly HolderBuilder DefaultHolderBuilder = new();

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", Justification = "Ignore")]
public Func<IResolver, object> CreateFactory(ConstructorInfo ci, Func<IResolver, object>[] factories, Action<IResolver, object>[] actions)
public Func<IResolver, object> CreateFactory(ConstructorInfo ci, Func<IResolver, object?>[] factories, Action<IResolver, object>[] actions)
{
var holder = DefaultHolderBuilder.CreateHolder(factories, actions);
var holderType = holder?.GetType() ?? typeof(object);
Expand Down Expand Up @@ -145,7 +145,7 @@ private ModuleBuilder ModuleBuilder
}
}

public object? CreateHolder(Func<IResolver, object>[] factories, Action<IResolver, object>[] actions)
public object? CreateHolder(Func<IResolver, object?>[] factories, Action<IResolver, object>[] actions)
{
if ((factories.Length == 0) && (actions.Length == 0))
{
Expand Down
2 changes: 1 addition & 1 deletion Smart.Resolver/Resolver/Builders/IFactoryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Smart.Resolver.Builders

public interface IFactoryBuilder
{
Func<IResolver, object> CreateFactory(ConstructorInfo ci, Func<IResolver, object>[] factories, Action<IResolver, object>[] actions);
Func<IResolver, object> CreateFactory(ConstructorInfo ci, Func<IResolver, object?>[] factories, Action<IResolver, object>[] actions);

Func<IResolver, object> CreateArrayFactory(Type type, Func<IResolver, object>[] factories);
}
Expand Down
Loading

0 comments on commit d3f3aa0

Please sign in to comment.