Ejemplo n.º 1
0
 public EvaluationContext(
     string name,
     ISpiceNetlistCaseSensitivitySettings caseSettings,
     IRandomizer randomizer,
     IExpressionParserFactory expressionParserFactory,
     IExpressionFeaturesReader expressionFeaturesReader,
     IExpressionValueProvider expressionValueProvider,
     INameGenerator nameGenerator,
     IResultService resultService)
 {
     _caseSettings            = caseSettings;
     ExpressionParserFactory  = expressionParserFactory;
     ExpressionFeaturesReader = expressionFeaturesReader;
     ExpressionValueProvider  = expressionValueProvider;
     NameGenerator            = nameGenerator;
     ResultService            = resultService;
     Name               = name;
     Parameters         = new Dictionary <string, Expression>(StringComparerProvider.Get(caseSettings.IsParameterNameCaseSensitive));
     Arguments          = new Dictionary <string, Expression>(StringComparerProvider.Get(caseSettings.IsParameterNameCaseSensitive));
     Functions          = new Dictionary <string, List <IFunction> >(StringComparerProvider.Get(caseSettings.IsFunctionNameCaseSensitive));
     Children           = new List <EvaluationContext>();
     ExpressionRegistry = new ExpressionRegistry(caseSettings.IsParameterNameCaseSensitive, caseSettings.IsExpressionNameCaseSensitive);
     FunctionsBody      = new Dictionary <string, string>();
     FunctionArguments  = new Dictionary <string, List <string> >();
     Randomizer         = randomizer;
 }
Ejemplo n.º 2
0
        /// <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);
        }