public static Object GetValueFromObject( Object Obj, String PropertyPath, Int32 ParametersCount, Boolean ExtenderExists, out Boolean FoundValue) { FoundValue = false; if (Obj == null) { FoundValue = true; return(null); } if (Obj is EmptyObject) { throw new NotImplementedException(); } if (Obj is IDictionaryWithGetter) { IDictionaryWithGetter dict = Obj as IDictionaryWithGetter; Boolean contains = dict.Contains(PropertyPath); if ((contains || !ExtenderExists) && dict.CanGetValueFromDictionary(PropertyPath)) { FoundValue = true; return(dict.GetValueFromDictionary(PropertyPath)); } } else if (Obj is IDictionary) { IDictionary dict = Obj as IDictionary; if (dict.Contains(PropertyPath)) { FoundValue = true; return(dict[PropertyPath]); } } else if (Obj is IDictionary <string, object> ) { IDictionary <string, object> dict = Obj as IDictionary <string, object>; if (dict.ContainsKey(PropertyPath)) { FoundValue = true; return(dict[PropertyPath]); } } else if (Obj is DynLanObject) { #if CASE_INSENSITIVE PropertyPath = PropertyPath.ToUpper(); #endif DynLanObject DynLanObj = Obj as DynLanObject; if (DynLanObj.Contains(PropertyPath)) { FoundValue = true; return(DynLanObj[PropertyPath]); } } Object val = RefSensitiveHelper.I.GetValueOrMethod( Obj, PropertyPath, ParametersCount, out FoundValue); return(val); }
//////////////////////////////////////////////////////////////////////// public static Object Execute(DynContext EvaluateContext, Object obj, IList <Object> Parameters) { Object Collection = obj; #if !NET20 Object Key = Parameters == null ? null : Parameters.FirstOrDefault(); #else Object Key = Parameters == null ? null : Linq2.FirstOrDefault(Parameters); #endif 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 DynLanObject) { DynLanObject DynLanObj = Collection as DynLanObject; if (DynLanObj.TotalCount == 0) { return(null); } /*IDictionary<String, Object> dict = ((DynLanObject)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(DynLanObj[finalKey]); } if (Collection is IDictionaryWithGetter) { IDictionaryWithGetter dict = Collection as IDictionaryWithGetter; if (dict.CanGetValueFromDictionary(Key)) { return(dict.GetValueFromDictionary(Key)); } } else 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]); } else if (Collection is IDictionary <string, object> ) { IDictionary <string, object> dict = (IDictionary <string, object>)Collection; if (dict.Count == 0) { return(null); } return(dict[UniConvert.ToString(Key)]); } 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); }