mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
enable disposing ITypeResolver
This commit is contained in:

committed by
Patrik Svensson

parent
1ed7e65fcb
commit
6bceac8a5e
@ -76,7 +76,7 @@ namespace Spectre.Console.Cli
|
||||
_registrar.RegisterInstance(typeof(IRemainingArguments), parsedResult.Remaining);
|
||||
|
||||
// Create the resolver and the context.
|
||||
var resolver = new TypeResolverAdapter(_registrar.Build());
|
||||
using var resolver = new TypeResolverAdapter(_registrar.Build());
|
||||
var context = new CommandContext(parsedResult.Remaining, leaf.Command.Name, leaf.Command.Data);
|
||||
|
||||
// Execute the command tree.
|
||||
|
@ -2,7 +2,7 @@ using System;
|
||||
|
||||
namespace Spectre.Console.Cli
|
||||
{
|
||||
internal sealed class TypeResolverAdapter : ITypeResolver
|
||||
internal sealed class TypeResolverAdapter : ITypeResolver, IDisposable
|
||||
{
|
||||
private readonly ITypeResolver? _resolver;
|
||||
|
||||
@ -43,5 +43,13 @@ namespace Spectre.Console.Cli
|
||||
throw CommandRuntimeException.CouldNotResolveType(type, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_resolver is IDisposable disposable)
|
||||
{
|
||||
disposable.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user