////////////////////////////////////////////// public static PainContext InvokeObjectMethodGetContext( this PainObject Object, PainContext PainContext, String Method, IList <Object> MethodParameters, IDictionary <String, Object> StaticValues = null) { return(InvokeObjectMethodGetContext( Object, Method, MethodParameters, PainContext != null && PainContext.GlobalObject != null ? PainContext.GlobalObject.DynamicValues : null, StaticValues)); }
public static Object GetValueFromObject( Object Obj, String PropertyPath, Int32 ParametersCount, out Boolean FoundValue) { FoundValue = false; if (Obj == null) { FoundValue = true; return(null); } if (Obj is EmptyObject) { throw new NotImplementedException(); } if (Obj is IDictionary) { IDictionary dict = Obj as IDictionary; if (dict.Contains(PropertyPath)) { FoundValue = true; return(dict[PropertyPath]); } } else if (Obj is PainObject) { PropertyPath = PropertyPath.ToUpper(); PainObject painObj = Obj as PainObject; if (painObj.Contains(PropertyPath)) { FoundValue = true; return(painObj[PropertyPath]); } } return(RefUnsensitiveHelper.I.GetValueOrMethod( Obj, PropertyPath, ParametersCount, out FoundValue)); }
public static Object InvokeObjectMethod( this PainObject Object, PainContext PainContext, String Method, IList <Object> MethodParameters, IDictionary <String, Object> StaticValues = null) { using (PainContext context = InvokeObjectMethodGetContext( Object, PainContext, Method, MethodParameters, StaticValues)) { return(context.Eval()); } }
//////////////////////////////////////////////////////////////////////// public static Object Execute(PainContext EvaluateContext, Object obj, IList <Object> Parameters) { Boolean isValueSet = false; String propertyPath = UniConvert.ToUniString(Parameters != null && Parameters.Count > 0 ? Parameters[0] : null); Object value = (Parameters != null && Parameters.Count > 1 ? Parameters[1] : null); if (obj is IDictionary) { IDictionary dict = obj as IDictionary; dict[propertyPath] = value; isValueSet = true; } if (obj is PainObject) { propertyPath = propertyPath.ToUpper(); PainObject painObj = obj as PainObject; painObj[propertyPath] = value; return(null); } if (!isValueSet) { isValueSet = RefSensitiveHelper.I.SetValue(obj, propertyPath, value); } if (!isValueSet) { isValueSet = RefUnsensitiveHelper.I.SetValue(obj, propertyPath, value); } if (isValueSet) { return(value); } return(null); }
//////////////////////////////////////////////////////////////////////// public static Object Execute(PainContext EvaluateContext, Object obj, IList <Object> Parameters) { Object Collection = obj; Object value = Parameters != null && Parameters.Count > 0 ? Parameters[0] : null; Object Key = Parameters != null && Parameters.Count > 1 ? Parameters[1] : null; if (Collection == null) { return(null); } if (Collection is PainObject) { PainObject painObj = Collection as PainObject; String finalKey = (String)(Key.GetType() == typeof(String) ? Key : Convert.ChangeType(Key, typeof(String), System.Globalization.CultureInfo.InvariantCulture)); Object finValue = value == null ? null : (value.GetType() == typeof(Object) ? value : Convert.ChangeType(value, typeof(Object), System.Globalization.CultureInfo.InvariantCulture)); painObj[finalKey] = finValue; return(value); } if (Collection is IDictionary) { IDictionary dict = (IDictionary)Collection; Type[] arguments = dict.GetType().GetGenericArguments(); Type keyType = arguments[0]; Type valueType = arguments[1]; Object finalKey = Key.GetType() == keyType ? Key : Convert.ChangeType(Key, keyType, System.Globalization.CultureInfo.InvariantCulture); Object finValue = value == null ? null : (value.GetType() == valueType ? value : Convert.ChangeType(value, valueType, System.Globalization.CultureInfo.InvariantCulture)); lock (dict) { dict.Remove(finalKey); dict.Add(finalKey, finValue); } return(value); } if (Collection is IList) { Int32?index = UniConvert.ToInt32N(Key); if (index == null || index < 0) { return(null); } IList list = (IList)Collection; if (index >= list.Count) { return(null); } Type listType = MyTypeHelper.GetListType(list); Object finValue = value == null ? null : (value.GetType() == listType ? value : Convert.ChangeType(value, listType, System.Globalization.CultureInfo.InvariantCulture)); list[index.Value] = finValue; return(value); } return(null); }
//////////////////////////////////////////////////////////////////////// public static Object Execute(PainContext EvaluateContext, Object obj, IList <Object> Parameters) { Object Collection = obj; Object Key = Parameters == null ? null : Parameters.FirstOrDefault(); if (Collection == null) { return(null); } if (Collection is String) { Int32?index = UniConvert.ToInt32N(Key); if (index == null || index < 0) { return(null); } String str = (String)Collection; if (index >= str.Length) { return(null); } return(str[index.Value]); } if (Collection is PainObject) { PainObject painObj = Collection as PainObject; if (painObj.TotalCount == 0) { return(null); } /*IDictionary<String, Object> dict = ((PainObject)Collection).Values; * if (dict.Count == 0) * return null;*/ String finalKey = ((String)(Key.GetType() == typeof(String) ? Key : Convert.ChangeType(Key, typeof(String), System.Globalization.CultureInfo.InvariantCulture))); return(painObj[finalKey]); } if (Collection is IDictionary) { IDictionary dict = (IDictionary)Collection; if (dict.Count == 0) { return(null); } Type[] arguments = dict.GetType().GetGenericArguments(); Type keyType = arguments[0]; Object finalKey = Key.GetType() == keyType ? Key : Convert.ChangeType(Key, keyType, System.Globalization.CultureInfo.InvariantCulture); return(dict[finalKey]); } if (Collection is IList) { Int32?index = UniConvert.ToInt32N(Key); if (index == null || index < 0) { return(null); } IList list = (IList)Collection; if (index >= list.Count) { return(null); } return(list[index.Value]); } if (Collection is IEnumerable) { Int32?index = UniConvert.ToInt32N(Key); if (index == null || index < 0) { return(null); } Int32 i = -1; foreach (Object item in ((IEnumerable)Collection)) { i++; if (i == index.Value) { return(item); } } } return(null); }
private static PainContext InvokeMethodGetContext( String Method, IList <Object> MethodParameters, IDictionary <String, Object> Values, IDictionary <String, Object> StaticValues) { PainContext newContext = CreateContext( new PainCodeLines(), Values, StaticValues, false, true); PainObject globalObject = newContext.GlobalObject; ExpressionGroup expressionGroup = new ExpressionGroup(false); expressionGroup.MainExpression = new Expression(); expressionGroup.MainExpression.IsOnpExecution = false; expressionGroup.MainExpression.Tokens = new ExpressionTokens(); expressionGroup.MainExpression.Tokens.Add( new ExpressionToken(Method, TokenType.VARIABLE)); expressionGroup.MainExpression.Tokens.Add( new ExpressionToken('@', TokenType.OPERATOR)); expressionGroup.MainExpression.Tokens.Add( new ExpressionToken('(', TokenType.BRACKET_BEGIN)); if (MethodParameters != null) { Int32 i = -1; foreach (Object parameter in MethodParameters) { i++; if (i > 0) { expressionGroup.MainExpression.Tokens.Add( new ExpressionToken(',', TokenType.SEPARATOR)); } String parameterName = IdGenerator.Generate(); globalObject.DynamicValues[parameterName] = parameter; // much faster //newContext[parameterName] = parameter; expressionGroup.MainExpression.Tokens.Add( new ExpressionToken(parameterName, TokenType.VARIABLE)); } } expressionGroup.MainExpression.Tokens.Add( new ExpressionToken(')', TokenType.BRACKET_END)); PainCodeLine lineOfCode = new PainCodeLine() { ExpressionGroup = expressionGroup, Depth = 0, IsLineEmpty = false, OperatorType = EOperatorType.RETURN }; newContext.GlobalState.Program.Lines.Add(lineOfCode); return(newContext); }