public override bool TryGetMember(GetMemberBinder binder, out object result) { result = null; if (_rawData.Count > 0) { if (!_rawData.TryGetValue(binder.Name, out result)) { return(false); } if (result is IDictionary <string, object> && ((IDictionary <string, object>)result).Count > 0) { result = new DynamicJsonObject((IDictionary <string, object>)result); } else if (result is ArrayList && ((ArrayList)result).Count > 0) { ArrayList iterate = result as ArrayList; IDictionary <string, object> res = new Dictionary <string, object>(iterate.Count); for (int i = 0; i < iterate.Count; i++) { res.Add(i.ToString(), iterate[i]); } result = new DynamicJsonObject((IDictionary <string, object>)res); } return(true); } return(false); }
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result) { result = null; if (indexes != null && indexes.Length > 0 && indexes[0] != null) { if (typeof(int) == indexes[0].GetType()) { int index = (((int)indexes[0]) >= 0) ? ((int)indexes[0]) : 0; List <object> values = new List <object>(_rawData.Values); result = values[index]; } else if (typeof(string) == indexes[0].GetType()) { string key = indexes[0] as string; if (_rawData.ContainsKey(key)) { result = _rawData[key]; } } } if (result != null) { if (result is IDictionary <string, object> && ((IDictionary <string, object>)result).Count > 0) { result = new DynamicJsonObject((IDictionary <string, object>)result); } else if (result is ArrayList && ((ArrayList)result).Count > 0) { ArrayList iterate = result as ArrayList; IDictionary <string, object> res = new Dictionary <string, object>(iterate.Count); for (int i = 0; i < iterate.Count; i++) { res.Add(i.ToString(), iterate[i]); } result = new DynamicJsonObject((IDictionary <string, object>)res); } return(true); } return(false); }