public override RuntimeValue Evaluate(IOtterContext context)
#endif
        {
            if (string.IsNullOrEmpty(this.VariableName))
            {
                return(false);
            }

            RuntimeValueType[] types;
            if (string.Equals(this.VariableType, "scalar", StringComparison.OrdinalIgnoreCase))
            {
                types = new[] { RuntimeValueType.Scalar }
            }
            ;
            else if (string.Equals(this.VariableType, "vector", StringComparison.OrdinalIgnoreCase))
            {
                types = new[] { RuntimeValueType.Vector }
            }
            ;
            else if (string.Equals(this.VariableType, "map", StringComparison.OrdinalIgnoreCase))
            {
                types = new[] { RuntimeValueType.Map }
            }
            ;
            else
            {
                types = new[] { RuntimeValueType.Scalar, RuntimeValueType.Vector, RuntimeValueType.Map }
            };

            var execContext = context as IOperationExecutionContext;

            if (execContext == null)
            {
                return(null);
            }

            foreach (var type in types)
            {
                var variableName = new RuntimeVariableName(this.VariableName, type);
                var value        = execContext.TryGetVariableValue(variableName);
                if (value != null)
                {
                    return(value.Value);
                }

                var functionValue = execContext.TryGetFunctionValue(variableName.ToString());
                if (functionValue != null)
                {
                    return(functionValue.Value);
                }
            }

            return(null);
        }
    }
Ejemplo n.º 2
0
 private static RuntimeValue?TryGetFunctionValue(RuntimeVariableName functionName, IOperationExecutionContext context)
 {
     try
     {
         return(context.TryGetFunctionValue(functionName.ToString()));
     }
     catch
     {
         return(null);
     }
 }
Ejemplo n.º 3
0
        protected override object EvaluateScalar(object context)
        {
            if (string.IsNullOrEmpty(this.VariableName))
            {
                return(false);
            }

            RuntimeValueType[] types;
            if (string.Equals(this.VariableType, "scalar", StringComparison.OrdinalIgnoreCase))
            {
                types = new[] { RuntimeValueType.Scalar }
            }
            ;
            else if (string.Equals(this.VariableType, "vector", StringComparison.OrdinalIgnoreCase))
            {
                types = new[] { RuntimeValueType.Vector }
            }
            ;
            else if (string.Equals(this.VariableType, "map", StringComparison.OrdinalIgnoreCase))
            {
                types = new[] { RuntimeValueType.Map }
            }
            ;
            else
            {
                types = new[] { RuntimeValueType.Scalar, RuntimeValueType.Vector, RuntimeValueType.Map }
            };

            var execContext = context as IOperationExecutionContext;

            foreach (var type in types)
            {
                var variableName = new RuntimeVariableName(this.VariableName, type);
                if (execContext.TryGetVariableValue(variableName) != null)
                {
                    return(true);
                }

                if (execContext.TryGetFunctionValue(variableName.ToString()) != null)
                {
                    return(true);
                }
            }

            return(false);
        }
    }