public bool HaveSpiceProperties(string expression, EvaluationContext context)
        {
            var parser    = _factory.Create(context, false);
            var variables = parser.GetVariables(expression);

            var voltageExportFactory = new VoltageExporter();
            var currentExportFactory = new CurrentExporter();

            foreach (var variable in variables)
            {
                var variableName = variable.ToLower();

                if (currentExportFactory.CreatedTypes.Any(type => variableName.StartsWith(type)))
                {
                    return(true);
                }

                if (voltageExportFactory.CreatedTypes.Any(type => variableName.StartsWith(type)))
                {
                    return(true);
                }
            }

            return(false);
        }
        public bool HaveSpiceProperties(string expression, EvaluationContext context)
        {
            bool present = false;
            var  parser  = _factory.Create(context);

            parser.SpicePropertyFound += (sender, e) =>
            {
                present = true;
                e.Apply(() => 0);
            };

            parser.Parse(expression);
            return(present);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MathExpressionCompiler" /> class.
        /// </summary>
        /// <param name="charComparer">The character comparer.</param>
        /// <param name="parserFactory">The parser factory.</param>
        public MathExpressionCompiler(IEqualityComparer <char> charComparer, IExpressionParserFactory parserFactory)
        {
            charComparer ??= CharComparer.Ordinal;
            var comparer = new SourceCodeFragmentContentComparer(charComparer);

            _functionsByNameByArgCount = new Dictionary <IReadOnlyList <char>, Dictionary <int, Func <object[], object> > >(comparer);

            _variables = new Dictionary <IReadOnlyList <char>, Func <object> >(comparer);
            _constants = new Dictionary <IReadOnlyList <char>, object>(comparer);

            _parser = parserFactory.Create(this, this, charComparer);
        }
Exemple #4
0
 public double GetExpressionValue(string expression, EvaluationContext context, bool @throw = true)
 {
     try
     {
         var parser = _parserFactory.Create(context, @throw, true);
         return(parser.Parse(expression));
     }
     catch
     {
         if (@throw)
         {
             throw;
         }
         else
         {
             return(double.NaN);
         }
     }
 }