From a409f2443ff747961c8885e4bbb5192b5ecba81f Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 13 Apr 2020 09:10:52 -0700 Subject: [PATCH] fix nullability --- src/System.CommandLine/Binding/BindingContext.cs | 4 ++-- src/System.CommandLine/Invocation/ServiceProvider.cs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/System.CommandLine/Binding/BindingContext.cs b/src/System.CommandLine/Binding/BindingContext.cs index 850712d4d5..3f620eea24 100644 --- a/src/System.CommandLine/Binding/BindingContext.cs +++ b/src/System.CommandLine/Binding/BindingContext.cs @@ -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 { @@ -70,7 +70,7 @@ public void AddService(Func factory) throw new ArgumentNullException(nameof(factory)); } - ServiceProvider.AddService(typeof(T), s => factory(s)!); + ServiceProvider.AddService(typeof(T), s => factory(s)); } internal bool TryGetValueSource( diff --git a/src/System.CommandLine/Invocation/ServiceProvider.cs b/src/System.CommandLine/Invocation/ServiceProvider.cs index 86970c5a76..d7fae863bb 100644 --- a/src/System.CommandLine/Invocation/ServiceProvider.cs +++ b/src/System.CommandLine/Invocation/ServiceProvider.cs @@ -13,11 +13,11 @@ namespace System.CommandLine.Invocation { internal class ServiceProvider : IServiceProvider { - private readonly Dictionary> _services; + private readonly Dictionary> _services; public ServiceProvider(BindingContext bindingContext) { - _services = new Dictionary> + _services = new Dictionary> { [typeof(ParseResult)] = _ => bindingContext.ParseResult, [typeof(IConsole)] = _ => bindingContext.Console, @@ -29,18 +29,18 @@ public ServiceProvider(BindingContext bindingContext) public void AddService(Func factory) => _services[typeof(T)] = p => factory(p)!; - public void AddService(Type serviceType, Func factory) => _services[serviceType] = factory; + public void AddService(Type serviceType, Func factory) => _services[serviceType] = factory; public IReadOnlyCollection 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; } } }