//////////////////////////////////////////////////////////////////////// public static Object Execute(DynContext 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 IDictionaryWithGetter) { IDictionaryWithGetter dict = obj as IDictionaryWithGetter; if (dict.CanSetValueToDictionary(propertyPath)) { dict[propertyPath] = value; isValueSet = true; } } else if (obj is IDictionary) { IDictionary dict = obj as IDictionary; dict[propertyPath] = value; isValueSet = true; } else if (obj is IDictionary <string, object> ) { IDictionary <string, object> dict = obj as IDictionary <string, object>; dict[propertyPath] = value; isValueSet = true; } if (obj is DynLanObject) { #if CASE_INSENSITIVE propertyPath = propertyPath.ToUpper(); #endif DynLanObject DynLanObj = obj as DynLanObject; DynLanObj[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(DynContext 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 DynLanObject) { DynLanObject DynLanObj = Collection as DynLanObject; 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)); DynLanObj[finalKey] = finValue; return(value); } if (Collection is IDictionaryWithGetter) { IDictionaryWithGetter dict = (IDictionaryWithGetter)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)); if (dict.CanSetValueToDictionary(finalKey)) { lock (dict) { dict.Remove(finalKey); dict.Add(finalKey, finValue); } } return(value); } else 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); } else if (Collection is IDictionary <string, object> ) { IDictionary <string, object> dict = (IDictionary <string, object>)Collection; lock (dict) { string finalKey = UniConvert.ToString(Key); dict.Remove(finalKey); dict.Add(finalKey, value); } 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); }