Skip to content

Commit

Permalink
fix nullability
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Apr 13, 2020
1 parent ba783e4 commit a409f24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/System.CommandLine/Binding/BindingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public BindingContext(

internal IConsoleFactory? ConsoleFactory { get; set; }

internal IHelpBuilder HelpBuilder => (IHelpBuilder)ServiceProvider.GetService(typeof(IHelpBuilder));
internal IHelpBuilder HelpBuilder => (IHelpBuilder)ServiceProvider.GetService(typeof(IHelpBuilder))!;

public IConsole Console
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public void AddService<T>(Func<IServiceProvider, T> factory)
throw new ArgumentNullException(nameof(factory));
}

ServiceProvider.AddService(typeof(T), s => factory(s)!);
ServiceProvider.AddService(typeof(T), s => factory(s));
}

internal bool TryGetValueSource(
Expand Down
10 changes: 5 additions & 5 deletions src/System.CommandLine/Invocation/ServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace System.CommandLine.Invocation
{
internal class ServiceProvider : IServiceProvider
{
private readonly Dictionary<Type, Func<IServiceProvider, object>> _services;
private readonly Dictionary<Type, Func<IServiceProvider, object?>> _services;

public ServiceProvider(BindingContext bindingContext)
{
_services = new Dictionary<Type, Func<IServiceProvider, object>>
_services = new Dictionary<Type, Func<IServiceProvider, object?>>
{
[typeof(ParseResult)] = _ => bindingContext.ParseResult,
[typeof(IConsole)] = _ => bindingContext.Console,
Expand All @@ -29,18 +29,18 @@ public ServiceProvider(BindingContext bindingContext)

public void AddService<T>(Func<IServiceProvider, T> factory) => _services[typeof(T)] = p => factory(p)!;

public void AddService(Type serviceType, Func<IServiceProvider, object> factory) => _services[serviceType] = factory;
public void AddService(Type serviceType, Func<IServiceProvider, object?> factory) => _services[serviceType] = factory;

public IReadOnlyCollection<Type> AvailableServiceTypes => _services.Keys;

public object GetService(Type serviceType)
public object? GetService(Type serviceType)
{
if (_services.TryGetValue(serviceType, out var factory))
{
return factory(this);
}

return null!;
return null;
}
}
}

0 comments on commit a409f24

Please sign in to comment.