using System;
using System.Collections.Generic;
//using System.Dynamic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Nethereum.ABI.ABIDeserialisation
{
///
/// This is a replication (copy) of Newtonsoft ExpandoObjectConverter to allow for PCL compilaton
///
public class ExpandoObjectConverter : JsonConverter
{
///
/// Gets a value indicating whether this can write JSON.
///
///
/// true if this can write JSON; otherwise, false.
///
public override bool CanWrite
{
get { return false; }
}
///
/// Determines whether this instance can convert the specified object type.
///
/// Type of the object.
///
/// true if this instance can convert the specified object type; otherwise, false.
///
public override bool CanConvert(Type objectType)
{
return objectType == typeof(IDictionary);
}
///
/// Reads the JSON representation of the object.
///
/// The to read from.
/// Type of the object.
/// The existing value of object being read.
/// The calling serializer.
/// The object value.
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
JsonSerializer serializer)
{
return ReadValue(reader);
}
///
/// Writes the JSON representation of the object.
///
/// The to write to.
/// The value.
/// The calling serializer.
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
// can write is set to false
}
private bool IsPrimitiveToken(JsonToken token)
{
switch (token)
{
case JsonToken.Integer:
case JsonToken.Float:
case JsonToken.String:
case JsonToken.Boolean:
case JsonToken.Undefined:
case JsonToken.Null:
case JsonToken.Date:
case JsonToken.Bytes:
return true;
default:
return false;
}
}
private object ReadList(JsonReader reader)
{
IList