public UnityELExpression <T> CreateExpression <T>(string expression) { evaluator = new UnityELEvaluator(); evaluator.Properties["emptyString"] = ""; evaluator.Properties["string"] = "abc"; evaluator.Properties["emptyArray"] = new string[0]; evaluator.Properties["array"] = new string[] { "abc" }; evaluator.Properties["emptyList"] = new List <string>(); evaluator.Properties["list"] = new List <string> { "abc" }; evaluator.Properties["emptyDictionary"] = new Dictionary <string, string>(); evaluator.Properties["dictionary"] = new Dictionary <string, string> { { "abc", "123" } }; evaluator.Properties["emptySet"] = new HashSet <string>(); evaluator.Properties["set"] = new HashSet <string> { "abc" }; evaluator.Properties["emptyEnumerable"] = new TestObject(false); evaluator.Properties["enumerable"] = new TestObject(true); evaluator.Properties["emptyOther"] = null; evaluator.Properties["other"] = new OtherObject(); return(evaluator.Compile <T>(expression)); }
public void Init() { evaluator = new UnityELEvaluator(); functionResolver = new TestFunctionResolver(); evaluator.DefaultFunctionResolver = functionResolver; }
public override object Evaluate(UnityELEvaluator context) { object rhsResult = Rhs.Evaluate(context); float rhsFloat = TypeCoercer.CoerceToType <float>(this, rhsResult); return(-rhsFloat); }
public override object Evaluate(UnityELEvaluator context) { object rhsResult = Rhs.Evaluate(context); bool rhsBool = TypeCoercer.CoerceToType <bool>(this, rhsResult); return(!rhsBool); }
public override object Evaluate(UnityELEvaluator context) { object lhsResult = Lhs.Evaluate(context); object rhsResult = Rhs.Evaluate(context); return(lhsResult ?? rhsResult); }
public object Evaluate(UnityELEvaluator context, ArgumentGroupToken group) { int arg1 = TypeCoercer.CoerceToType <int>(group, group.Children[0].Evaluate(context)); int arg2 = TypeCoercer.CoerceToType <int>(group, group.Children[1].Evaluate(context)); return(new TestObject(arg1, arg2)); }
public override object Evaluate(UnityELEvaluator context) { object rhsResult = Rhs.Evaluate(context); int rhsInt = TypeCoercer.CoerceToType <int>(this, rhsResult); return(~rhsInt); }
private UnityELExpression <T> CreateExpression <T>(string expression) { evaluator = new UnityELEvaluator(); stringDictionary = new Dictionary <string, string>(); evaluator.Properties["stringDictionary"] = stringDictionary; stringList = new List <string>(); evaluator.Properties["stringList"] = stringList; stringArray = new string[1]; evaluator.Properties["stringArray"] = stringArray; intDictionary = new Dictionary <int, int>(); evaluator.Properties["intDictionary"] = intDictionary; intList = new List <int>(); evaluator.Properties["intList"] = intList; intArray = new int[1]; evaluator.Properties["intArray"] = intArray; testObject = new TestObject(); evaluator.Properties["testObject"] = testObject; return(evaluator.Compile <T>(expression)); }
public override object Evaluate(UnityELEvaluator context) { object amount = Rhs.Evaluate(context); float floatAmount = TypeCoercer.CoerceToType <float>(this, amount); float floatCurrent = 0; // If the value doesn't already exists (and we can detect that) we start with zero. bool readCurrentValue = true; if (Lhs is ExistsSupport) { readCurrentValue = ((ExistsSupport)Lhs).Exists(context); } if (readCurrentValue) { object current = Lhs.Evaluate(context); floatCurrent = TypeCoercer.CoerceToType <float>(this, current); } float result = floatCurrent + floatAmount; ((AssignableToken)Lhs).Assign(context, result); return(result); }
public UnityELExpression <T> CreateExpression <T>(string expression) { evaluator = new UnityELEvaluator(); evaluator.Properties["testObject"] = new TestObject(); evaluator.Properties["nullProperty"] = null; return(evaluator.Compile <T>(expression)); }
public override object Evaluate(UnityELEvaluator context) { object value = Rhs.Evaluate(context); ((AssignableToken)Lhs).Assign(context, value); return(value); }
public UnityELExpression <T> CreateExpression <T>(string expression) { evaluator = new UnityELEvaluator(); evaluator.ArgumentGroupEvaluator = new TestArgumentGroupEvaluator(); evaluator.DefaultFunctionResolver = new TestFunctionResolver(); return(evaluator.Compile <T>(expression)); }
/** * Specialised version of evaluate which is used when the argument group is evaluated in the scope of a function */ public object EvaluateForArgument(UnityELEvaluator context, string functionName, int argumentIndex) { if (context.ArgumentGroupEvaluator == null) { throw new ParserException(this, "Cannot convert argument group to an argument as no ArgumentGroupConverter has been configured on the evaluator"); } return(context.ArgumentGroupEvaluator.EvaluateForArgument(context, functionName, argumentIndex, this)); }
public override object Evaluate(UnityELEvaluator context) { if (context.ArgumentGroupEvaluator == null) { throw new ParserException(this, "Cannot convert argument group to a value as no ArgumentGroupConverter has been configured on the evaluator"); } return(context.ArgumentGroupEvaluator.Evaluate(context, this)); }
protected bool DoEvaluate(UnityELEvaluator context, object lhsResult) { Type lhsType = lhsResult?.GetType(); // Otherwise the rhs must identify the type to match object rhsResult = Rhs.Evaluate(context); if (rhsResult == null) { return(false); } string rhsString = TypeCoercer.CoerceToType <string>(this, rhsResult); // Special handling for some primitives if (rhsString.Equals("int", StringComparison.InvariantCultureIgnoreCase) || rhsString.Equals("integer", StringComparison.InvariantCultureIgnoreCase)) { // Is it an int? if (typeof(int).Equals(lhsType)) { return(true); } else if (typeof(float).Equals(lhsType)) { // We use floats internally, so we allow them to be considered as 'ints' if it would // not result in the loss of any data float floatValue = (float)lhsResult; int intValue = (int)floatValue; return(intValue == floatValue); } else { return(false); } } else if (rhsString.Equals("float", StringComparison.InvariantCultureIgnoreCase)) { // Allow floats or ints? return(typeof(float).Equals(lhsType) || typeof(int).Equals(lhsType)); } else if (rhsString.Equals("bool", StringComparison.InvariantCultureIgnoreCase) || rhsString.Equals("boolean", StringComparison.InvariantCultureIgnoreCase)) { return(typeof(bool).Equals(lhsType)); } else if (lhsType != null) { // Otherwise we must match the end of the type name return(lhsType.FullName.EndsWith(rhsString, StringComparison.InvariantCultureIgnoreCase)); } else { return(false); } }
public override object Evaluate(UnityELEvaluator context) { object lhsResult = Lhs.Evaluate(context); object rhsResult = Rhs.Evaluate(context); float lhsFloat = TypeCoercer.CoerceToType <float>(this, lhsResult); float rhsFloat = TypeCoercer.CoerceToType <float>(this, rhsResult); return(FastExponent(lhsFloat, rhsFloat)); }
public UnityELExpression <T> CreateExpression <T>(string expression) { evaluator = new UnityELEvaluator(); evaluator.Properties["nullLHS"] = null; evaluator.Properties["nonNullLHS"] = true; evaluator.Properties["nullRHS"] = null; evaluator.Properties["nonNullRHS"] = false; return(evaluator.Compile <T>(expression)); }
private void OnEnable() { InitialiseTextures(); //Application.logMessageReceivedThreaded += HandleLog; Clear(); evaluator = new UnityELEvaluator(); evaluator.DefaultFunctionResolver = new UnityFunctionResolver(this); evaluator.ArgumentGroupEvaluator = new UnityArgumentGroupEvaluator(); }
public override object Evaluate(UnityELEvaluator context) { if (context.Properties.ContainsKey(Value)) { return(context.Properties[Value]); } else { throw new NoSuchPropertyException(this, $"No property named: {Value} was known"); } }
public override object Evaluate(UnityELEvaluator context) { if (Rhs is ExistsSupport) { return(!((ExistsSupport)Rhs).Exists(context)); } else { throw new ParserException($"Unsupport token type for NotExists: {Rhs.Name}"); } }
public override object Evaluate(UnityELEvaluator context) { object host = Host.Evaluate(context); if (host == null) { return(null); } System.Type hostType = host.GetType(); object key = Children[0].Evaluate(context); System.Type keyType = key?.GetType(); // If the key is a string, we need to see if there is a property on the host that matches if (key is string) { PropertyInfo info = hostType.GetProperty((string)key); if (info != null) { return(info.GetValue(host)); } } // Otherwise inspect the host to determine what to do if (host is IDictionary) { IDictionary dictionary = (IDictionary)host; if (dictionary.Contains(key)) { return(dictionary[key]); } else { return(null); } } else if (host is IList) { IList list = (IList)host; int i = TypeCoercer.CoerceToType <int>(this, key); return(list[i]); } else if (host is Array) { Array array = (Array)host; int i = TypeCoercer.CoerceToType <int>(this, key); return(array.GetValue(i)); } throw new ParserException(this, $"Unsupported host value type: {hostType}, or unknown property: {key}"); }
public object EvaluateForArgument(UnityELEvaluator context, string functionname, int argumentIndex, ArgumentGroupToken group) { if (functionname.Equals("myFunction")) { int arg1 = TypeCoercer.CoerceToType <int>(group, group.Children[0].Evaluate(context)); int arg2 = TypeCoercer.CoerceToType <int>(group, group.Children[1].Evaluate(context)); return(new TestObject2(arg1, arg2)); } else { return(null); } }
public override object Evaluate(UnityELEvaluator context) { object testResult = Test.Evaluate(context); bool testBool = TypeCoercer.CoerceToType <bool>(this, testResult); if (testBool) { return(ResultIfTrue.Evaluate(context)); } else { return(ResultIfFalse.Evaluate(context)); } }
public override object Evaluate(UnityELEvaluator context) { FunctionDetails functionDetails = ResolveFunction(context); if (functionDetails.Function == null) { if (functionDetails.ResolutionFailedReason == null) { functionDetails.ResolutionFailedReason = $"Unable to resolve function: {functionDetails.Name} " + $"(host={functionDetails.Host})"; //, namespace={functionDetails.Namespace})"; } throw new NoSuchFunctionException(this, functionDetails.ResolutionFailedReason); } // Map parameters... MethodInfo function = functionDetails.Function; List <object> parameters = functionDetails.Parameters; ParameterInfo[] parameterInfos = function.GetParameters(); if (parameterInfos.Length > 0) { // If there is a different number of arguments, see if the last argument is a params // and then wrap up the required number of arguments in an array (coercing as needed) ParameterInfo lastParam = parameterInfos[parameterInfos.Length - 1]; if (lastParam.IsDefined(typeof(ParamArrayAttribute), false)) { int varargCount = parameters.Count - parameterInfos.Length + 1; Type elementType = lastParam.ParameterType.GetElementType(); Array varargs = Array.CreateInstance(elementType, varargCount); for (int i = 0; i < varargCount; ++i) { varargs.SetValue(TypeCoercer.CoerceToType(elementType, this, parameters[parameters.Count - varargCount + i]), i); } parameters[parameterInfos.Length - 1] = varargs; parameters.RemoveRange(parameterInfos.Length, parameters.Count - parameterInfos.Length); } // Coerce the parameters if needed for (int i = 0; i < parameters.Count; ++i) { parameters[i] = TypeCoercer.CoerceToType(parameterInfos[i].ParameterType, this, parameters[i]); } } return(function.Invoke(functionDetails.Host, parameters.ToArray())); }
public override object Evaluate(UnityELEvaluator context) { PropertyDetails details = ResolveProperty(context); if (details == null) { return(null); } else if (details.Property == null) { throw new NoSuchPropertyException(this, $"Property: {details.Name} not found on type: {details.HostType}"); } return(details.Property.GetValue(details.Host)); }
public UnityELExpression <T> CreateExpression <T>(string expression) { evaluator = new UnityELEvaluator(); evaluator.Properties["property"] = "anc"; evaluator.Properties["dictionary"] = new Dictionary <string, string> { { "key", "value" } }; evaluator.Properties["list"] = new List <string> { "abc" }; evaluator.Properties["array"] = new string[] { "abc" }; evaluator.Properties["object"] = new TestObject(); return(evaluator.Compile <T>(expression)); }
public object Evaluate(UnityELEvaluator context, ArgumentGroupToken group) { // Assume its a vector if there are three arguments if (group.Children.Count == 3) { float x = TypeCoercer.CoerceToType <float>(group, group.Children[0].Evaluate(context)); float y = TypeCoercer.CoerceToType <float>(group, group.Children[1].Evaluate(context)); float z = TypeCoercer.CoerceToType <float>(group, group.Children[2].Evaluate(context)); return(new Vector3(x, y, z)); } else { return(null); } }
private PropertyDetails ResolveProperty(UnityELEvaluator context) { PropertyDetails details = new PropertyDetails(); details.Host = Host.Evaluate(context); if (details.Host == null) { return(null); } details.Name = Property.Value; details.HostType = details.Host.GetType(); details.Property = details.HostType.GetProperty(details.Name); return(details); }
/** * Although this shares a fair bit of code with Evaluate, it is easier to read * as a separate method */ public bool Exists(UnityELEvaluator context) { object host = Host.Evaluate(context); if (host == null) { return(false); } System.Type hostType = host.GetType(); object key = Children[0].Evaluate(context); System.Type keyType = key?.GetType(); // If the key is a string, we need to see if there is a property on the host that matches if (key is string) { PropertyInfo info = hostType.GetProperty((string)key); if (info != null) { return(true); } } // Otherwise inspect the host to determine what to do if (host is IDictionary) { IDictionary dictionary = (IDictionary)host; return(dictionary.Contains(key)); } else if (host is IList) { IList list = (IList)host; int i = TypeCoercer.CoerceToType <int>(this, key); return(i < list.Count); } else if (host is Array) { Array array = (Array)host; int i = TypeCoercer.CoerceToType <int>(this, key); return(i < array.Length); } else { return(false); } }
public void Init() { evaluator = new UnityELEvaluator(); testObject = new TestObject(); evaluator.Properties["testObject"] = testObject; testDictionary = new Dictionary <string, object>(); testDictionary["testObject"] = testObject; evaluator.Properties["testDictionary"] = testDictionary; testArray = new TestObject[1]; testArray[0] = testObject; evaluator.Properties["testArray"] = testArray; testList = new List <TestObject>(); testList.Add(testObject); evaluator.Properties["testList"] = testList; }