using System; namespace QFSW.QC { /// /// Parser for all types inheriting from a single type. /// /// Base type of the types to parse. public abstract class PolymorphicQcParser : IQcParser where T : class { private Func _recursiveParser; public virtual int Priority => -1000; public bool CanParse(Type type) { return typeof(T).IsAssignableFrom(type); } public virtual object Parse(string value, Type type, Func recursiveParser) { _recursiveParser = recursiveParser; return Parse(value, type); } protected object ParseRecursive(string value, Type type) { return _recursiveParser(value, type); } protected TElement ParseRecursive(string value) { return (TElement)_recursiveParser(value, typeof(TElement)); } public abstract T Parse(string value, Type type); } }