using System;
using System.Collections.Generic;
namespace QFSW.QC
{
///
/// Parser for a single type.
/// Caches results and reuses them if the incoming string has already been parsed.
///
/// The type to parse.
public abstract class BasicCachedQcParser : BasicQcParser
{
private readonly Dictionary _cacheLookup = new Dictionary();
public override object Parse(string value, Type type, Func recursiveParser)
{
if (_cacheLookup.ContainsKey(value))
{
return _cacheLookup[value];
}
T result = (T)base.Parse(value, type, recursiveParser);
_cacheLookup[value] = result;
return result;
}
}
}