/// <summary>
 /// Initializes a new instance of the <see cref="MathExpressionParameterlessFunctionNode"/> class.
 /// </summary>
 /// <param name="expressionTypeId">The expression type identifier.</param>
 /// <param name="functionNameFragment">The function name fragment.</param>
 /// <param name="function">The function to evaluate function value.</param>
 /// <param name="valueTypeId">The value type identifier.</param>
 public MathExpressionParameterlessFunctionNode(
     string expressionTypeId,
     ISourceCodeFragment functionNameFragment,
     Func <object> function,
     string valueTypeId = null)
     : base(ExpressionTypeDescriptor.CreateExpressionClass(expressionTypeId, valueTypeId), functionNameFragment)
 {
     _function = function;
 }
예제 #2
0
        private static ExpressionTypeDescriptor CreateExpressionType(string ruleName, string valueTypeId = null)
        {
            if (String.IsNullOrEmpty(ruleName))
            {
                Guard.ArgNullOrEmpty(valueTypeId, nameof(valueTypeId));
                return(ExpressionTypeDescriptor.Undefined);
            }

            return(ExpressionTypeDescriptor.CreateExpressionClass(ruleName, valueTypeId));
        }
        private IParsingProduct GetFunction(
            ISourceCodeFragment functionName,
            string expressionTypeId,
            IEnumerable <IParsingProduct> arguments)
        {
            if (!_functionsByNameByArgCount.TryGetValue(functionName, out var functionByArgsCount))
            {
                return(null);
            }

            var args = arguments?.ToArray() ?? Array.Empty <IParsingProduct>();

            if (!functionByArgsCount.TryGetValue(args.Length, out var func))
            {
                return(null);
            }

            return(new MathExpressionFunctionNode(ExpressionTypeDescriptor.CreateExpressionClass(expressionTypeId), functionName, args, func));
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MathExpressionValueNode"/> class.
 /// </summary>
 /// <param name="expressionTypeId">The expression type identifier.</param>
 /// <param name="valueFragment">The source code fragment that represents the value.</param>
 /// <param name="value">The value.</param>
 /// <param name="valueTypeId">The value type identifier.</param>
 public MathExpressionValueNode(string expressionTypeId, ISourceCodeFragment valueFragment, object value, string valueTypeId = null)
     : base(ExpressionTypeDescriptor.CreateExpressionClass(expressionTypeId, valueTypeId), valueFragment)
 {
     _value = value;
 }