rabidus-test/Assets/Plugins/QFSW/Quantum Console/Source/Scripts/Parsing/BasicQcParser.cs

39 lines
990 B
C#
Raw Permalink Normal View History

2023-08-22 15:41:12 +03:00
using System;
namespace QFSW.QC
{
/// <summary>
/// Parser for a single type.
/// </summary>
/// <typeparam name="T">The type to parse.</typeparam>
public abstract class BasicQcParser<T> : IQcParser
{
private Func<string, Type, object> _recursiveParser;
public virtual int Priority => 0;
public bool CanParse(Type type)
{
return type == typeof(T);
}
public virtual object Parse(string value, Type type, Func<string, Type, object> recursiveParser)
{
_recursiveParser = recursiveParser;
return Parse(value);
}
protected object ParseRecursive(string value, Type type)
{
return _recursiveParser(value, type);
}
protected TElement ParseRecursive<TElement>(string value)
{
return (TElement)_recursiveParser(value, typeof(TElement));
}
public abstract T Parse(string value);
}
}