Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: a5e12002c2
Fetching contributors…

Cannot retrieve contributors at this time

55 lines (47 sloc) 1.543 kB
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System;
namespace twilio.sugar
{
public class DynamicJsonObject : DynamicObject
{
private readonly IDictionary<string, object> _dictionary;
public DynamicJsonObject(IDictionary<string, object> dictionary)
{
if (dictionary == null)
{
throw new ArgumentNullException("dictionary");
}
_dictionary = dictionary;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (!_dictionary.TryGetValue(binder.Name, out result))
{
result = null;
return true;
}
var dictionary = result as IDictionary<string, object>;
if (dictionary != null)
{
result = new DynamicJsonObject(dictionary);
return true;
}
var arrayList = result as ArrayList;
if (arrayList != null && arrayList.Count > 0)
{
if (arrayList[0] is IDictionary<string, object>)
{
result = new List<object>(arrayList.Cast<IDictionary<string, object>>().Select(x => new DynamicJsonObject(x)));
}
else
{
result = new List<object>(arrayList.Cast<object>());
}
}
return true;
}
}
}
Jump to Line
Something went wrong with that request. Please try again.