예제 #1
0
파일: dynamic.cs 프로젝트: joonhwan/NPoco
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (_dictionary.TryGetValue(binder.Name, out result) == false)
                if (_dictionary.TryGetValue(binder.Name.ToLower(), out result) == false)
                    return false;// throw new Exception("property not found " + binder.Name);

            if (result is IDictionary<string, object>)
            {
                result = new DynamicJson(result as IDictionary<string, object>);
            }
            else if (result is List<object>)
            {
                List<object> list = new List<object>();
                foreach (object item in (List<object>)result)
                {
                    if (item is IDictionary<string, object>)
                        list.Add(new DynamicJson(item as IDictionary<string, object>));
                    else
                        list.Add(item);
                }
                result = list;
            }

            return _dictionary.ContainsKey(binder.Name);
        }
예제 #2
0
파일: dynamic.cs 프로젝트: joonhwan/NPoco
 public override bool TryGetIndex(GetIndexBinder binder, Object[] indexes, out Object result)
 {
     var index = indexes[0];
     if (index is int)
     {
         result = _list[(int) index];
     }
     else
     {
         result = _dictionary[(string) index];
     }
     if (result is IDictionary<string, object>)
         result = new DynamicJson(result as IDictionary<string, object>);
     return true;
 }