All checks were successful
Run the JSON parser tests / test (push) Has been skipped
40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
namespace Jtr.Parsing;
|
|
|
|
public class VisitorContainer<TBase>
|
|
{
|
|
private Dictionary<Type, Visitor.Visit<TBase>> Visitors { get; } = new();
|
|
private Visitor.Visit<TBase> Default { get; set; } = default!;
|
|
|
|
public void Register<T>(Visitor.Visit<TBase> visitor)
|
|
{
|
|
Visitors[typeof(T)] = visitor;
|
|
}
|
|
|
|
public Visitor.Visit<TBase> this[Type type] => Visitors.GetValueOrDefault(type, Default);
|
|
}
|
|
|
|
public class VisitorContainer<TBase, TContext>
|
|
{
|
|
private Dictionary<Type, Visitor.Visit<TBase, TContext>> Visitors { get; } = new();
|
|
private Visitor.Visit<TBase, TContext> Default { get; set; } = default!;
|
|
|
|
public void Register<T>(Visitor.Visit<TBase, TContext> visitor)
|
|
{
|
|
Visitors[typeof(T)] = visitor;
|
|
}
|
|
|
|
public Visitor.Visit<TBase, TContext> this[Type type] => Visitors.GetValueOrDefault(type, Default);
|
|
}
|
|
|
|
public class VisitorContainer<TBase, TContext, TResult>
|
|
{
|
|
private Dictionary<Type, Visitor.Visit<TBase, TContext, TResult>> Visitors { get; } = new();
|
|
private Visitor.Visit<TBase, TContext, TResult> Default { get; set; } = default!;
|
|
|
|
public void Register<T>(Visitor.Visit<TBase, TContext, TResult> visitor)
|
|
{
|
|
Visitors[typeof(T)] = visitor;
|
|
}
|
|
|
|
public Visitor.Visit<TBase, TContext, TResult> this[Type type] => Visitors.GetValueOrDefault(type, Default);
|
|
} |