/// <summary> /// Clones the registry. /// </summary> /// <returns> /// A clone of registry. /// </returns> public ExpressionRegistry Clone() { var result = new ExpressionRegistry(IsParameterNameCaseSensitive, IsExpressionNameCaseSensitive); foreach (var parameter in Parameters) { result.Parameters[parameter.Key] = parameter.Value.Clone(); } foreach (var dep in ParametersDependencies) { result.ParametersDependencies[dep.Key] = new HashSet <string>(dep.Value); } List <Expression> addedExpressions = new List <Expression>(); foreach (var exprDep in ParametersExpressionsDependencies) { foreach (var expr in exprDep.Value) { if (!result.ParametersExpressionsDependencies.ContainsKey(exprDep.Key)) { result.ParametersExpressionsDependencies[exprDep.Key] = new List <Expression>(); } var clone = expr.Clone(); result.ParametersExpressionsDependencies[exprDep.Key].Add(clone); if (UnnamedExpressions.Contains(expr)) { result.UnnamedExpressions.Add(clone); addedExpressions.Add(expr); } if (expr is NamedExpression ne) { addedExpressions.Add(expr); result.NamedExpressions[ne.Name] = ne; } } } foreach (var expression in NamedExpressions) { if (!result.NamedExpressions.ContainsKey(expression.Key)) { result.NamedExpressions.Add(expression.Key, (NamedExpression)expression.Value.Clone()); } } foreach (var expression in UnnamedExpressions) { if (!addedExpressions.Contains(expression)) { result.UnnamedExpressions.Add(expression.Clone()); } } return(result); }
/// <summary> /// Adds an expression to registry. /// </summary> /// <param name="expression">Expression to add.</param> /// <param name="parameters">Parameters of the expression.</param> public void Add(Expression expression, ICollection <string> parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } foreach (var parameter in parameters) { if (!ParametersExpressionsDependencies.ContainsKey(parameter)) { ParametersExpressionsDependencies[parameter] = new List <Expression>(); } ParametersExpressionsDependencies[parameter].Add(expression); } UnnamedExpressions.Add(expression); }