using System; using System.Collections.Generic; using System.Reflection; namespace DynamicExpresso.Parsing { internal class ParserSettings { private readonly Dictionary _identifiers; private readonly Dictionary _knownTypes; private readonly HashSet _extensionMethods; public ParserSettings(bool caseInsensitive, bool lateBindObject) { CaseInsensitive = caseInsensitive; LateBindObject = lateBindObject; KeyComparer = CaseInsensitive ? StringComparer.InvariantCultureIgnoreCase : StringComparer.InvariantCulture; KeyComparison = CaseInsensitive ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture; _identifiers = new Dictionary(KeyComparer); _knownTypes = new Dictionary(KeyComparer); _extensionMethods = new HashSet(); AssignmentOperators = AssignmentOperators.All; DefaultNumberType = DefaultNumberType.Default; LambdaExpressions = false; } private ParserSettings(ParserSettings other) : this(other.CaseInsensitive, other.LateBindObject) { _knownTypes = new Dictionary(other._knownTypes, other._knownTypes.Comparer); _identifiers = new Dictionary(other._identifiers, other._identifiers.Comparer); _extensionMethods = new HashSet(other._extensionMethods); AssignmentOperators = other.AssignmentOperators; DefaultNumberType = other.DefaultNumberType; LambdaExpressions = other.LambdaExpressions; } /// /// Creates a deep copy of the current settings, so that the identifiers/types/methods can be changed /// without impacting the existing settings. /// public ParserSettings Clone() { return new ParserSettings(this); } public IDictionary KnownTypes { get { return _knownTypes; } } public IDictionary Identifiers { get { return _identifiers; } } public HashSet ExtensionMethods { get { return _extensionMethods; } } public bool CaseInsensitive { get; } public bool LateBindObject { get; } public StringComparison KeyComparison { get; } public IEqualityComparer KeyComparer { get; } public DefaultNumberType DefaultNumberType { get; set; } public AssignmentOperators AssignmentOperators { get; set; } public bool LambdaExpressions { get; set; } } }