mycroforge/MycroForge.CLI/Commands/OptionsContainer.cs
mdnapo 02a82589ae - Refactored init & features
- Extended documentation
2024-07-14 22:27:32 +02:00

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;
}
}