-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d3fd2e
commit c6c5918
Showing
4 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/BitzArt.ConsoleTools/Extensions/RunConsoleToolExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace BitzArt.ConsoleTools; | ||
|
||
public static class RunConsoleToolExtension | ||
{ | ||
public static void RunConsoleTool<TConsoleTool>(this IServiceProvider serviceProvider) | ||
where TConsoleTool : IConsoleTool | ||
{ | ||
var tool = serviceProvider.GetRequiredService<TConsoleTool>(); | ||
|
||
tool.Run(); | ||
} | ||
|
||
public static void RunConsoleTool(this IServiceProvider serviceProvider, Type type) | ||
{ | ||
if (!type.IsAssignableTo(typeof(IConsoleTool))) throw new ArgumentException($"Type must implement {nameof(IConsoleTool)} interface", nameof(type)); | ||
|
||
var tool = (IConsoleTool)serviceProvider.GetRequiredService(type); | ||
|
||
tool.Run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# BitzArt.ConsoleTools | ||
|
||
[![NuGet](https://img.shields.io/nuget/v/BitzArt.ConsoleTools.svg)](https://www.nuget.org/packages/BitzArt.ConsoleTools/) | ||
[![NuGet](https://img.shields.io/nuget/dt/BitzArt.ConsoleTools.svg)](https://www.nuget.org/packages/BitzArt.ConsoleTools/) | ||
|
||
Handy tools for .NET Core console applications. |