Use ValueTask

This commit is contained in:
Alexey Golub
2019-12-16 22:12:17 +02:00
parent d2b0b16121
commit 6ce52c70f7
32 changed files with 71 additions and 68 deletions

View File

@@ -3,12 +3,12 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>

View File

@@ -31,7 +31,7 @@ namespace CliFx.Demo.Commands
_libraryService = libraryService;
}
public Task ExecuteAsync(IConsole console)
public ValueTask ExecuteAsync(IConsole console)
{
// To make the demo simpler, we will just generate random publish date and ISBN if they were not set
if (Published == default)
@@ -48,7 +48,7 @@ namespace CliFx.Demo.Commands
console.Output.WriteLine("Book added.");
console.RenderBook(book);
return Task.CompletedTask;
return default;
}
}

View File

@@ -20,7 +20,7 @@ namespace CliFx.Demo.Commands
_libraryService = libraryService;
}
public Task ExecuteAsync(IConsole console)
public ValueTask ExecuteAsync(IConsole console)
{
var book = _libraryService.GetBook(Title);
@@ -29,7 +29,7 @@ namespace CliFx.Demo.Commands
console.RenderBook(book);
return Task.CompletedTask;
return default;
}
}
}

View File

@@ -16,7 +16,7 @@ namespace CliFx.Demo.Commands
_libraryService = libraryService;
}
public Task ExecuteAsync(IConsole console)
public ValueTask ExecuteAsync(IConsole console)
{
var library = _libraryService.GetLibrary();
@@ -32,7 +32,7 @@ namespace CliFx.Demo.Commands
console.RenderBook(book);
}
return Task.CompletedTask;
return default;
}
}
}

View File

@@ -19,7 +19,7 @@ namespace CliFx.Demo.Commands
_libraryService = libraryService;
}
public Task ExecuteAsync(IConsole console)
public ValueTask ExecuteAsync(IConsole console)
{
var book = _libraryService.GetBook(Title);
@@ -30,7 +30,7 @@ namespace CliFx.Demo.Commands
console.Output.WriteLine($"Book {Title} removed.");
return Task.CompletedTask;
return default;
}
}
}

View File

@@ -25,11 +25,11 @@ namespace CliFx.Demo
return services.BuildServiceProvider();
}
public static Task<int> Main(string[] args)
public static async Task<int> Main(string[] args)
{
var serviceProvider = ConfigureServices();
return new CliApplicationBuilder()
return await new CliApplicationBuilder()
.AddCommandsFromThisAssembly()
.UseCommandFactory(schema => (ICommand) serviceProvider.GetRequiredService(schema.Type))
.Build()