Inheritance: System.Dynamic.DynamicObject
Exemple #1
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (this.Dictionary.TryGetValue(binder.Name, out result) == false)
                if (this.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 this.Dictionary.ContainsKey(binder.Name);
        }
Exemple #2
0
 public override bool TryGetIndex(GetIndexBinder binder, Object[] indexes, out Object result)
 {
     int index = (int)indexes[0];
     result = _list[index];
     if (result is IDictionary<string, object>)
         result = new DynamicJson(result as IDictionary<string, object>);
     return true;
 }
Exemple #3
0
 public override bool TryGetIndex(GetIndexBinder binder, Object[] indexes, out Object result)
 {
     var index = (int)indexes[0];
     result = _list[index];
     var objects = result as IDictionary<string, object>;
     if (objects != null)
         result = new DynamicJson(objects);
     return true;
 }
Exemple #4
0
 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;
 }
Exemple #5
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (this.Dictionary.TryGetValue(binder.Name, out result) == false)
                if (this.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> && (result as List<object>).First() is IDictionary<string, object>)
                result = new List<DynamicJson>((result as List<object>).Select(x => new DynamicJson(x as IDictionary<string, object>)));

            else if (result is List<object>)
                result = result as List<object>;

            return this.Dictionary.ContainsKey(binder.Name);
        }
Exemple #6
0
        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);

            var objects = result as IDictionary<string, object>;
            if (objects != null)
            {
                result = new DynamicJson(objects);
            }
            else if (result is List<object>)
            {
                var list = 
                    (from item in (List<object>) result
                     let dictionary = item as IDictionary<string, object>
                     select dictionary != null ? new DynamicJson(dictionary) : item).ToList();
                result = list;
            }

            return _dictionary.ContainsKey(binder.Name);
        }