25 lines
551 B
C#
25 lines
551 B
C#
namespace MycroForge.CLI.Commands;
|
|
|
|
public class OptionsContainer
|
|
{
|
|
private readonly Dictionary<Type, object> _args = new();
|
|
|
|
public void Set<T>(T? args)
|
|
{
|
|
if (args is null)
|
|
throw new ArgumentNullException();
|
|
|
|
_args[args.GetType()] = args;
|
|
}
|
|
|
|
public T Get<T>()
|
|
{
|
|
if (!_args.ContainsKey(typeof(T)))
|
|
throw new KeyNotFoundException();
|
|
|
|
if (_args[typeof(T)] is not T args)
|
|
throw new InvalidCastException();
|
|
|
|
return args;
|
|
}
|
|
} |