Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json;
using System;

namespace Amazon.JSII.JsonModel.Api.Response
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Amazon.JSII.JsonModel.Converters;
using Newtonsoft.Json;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Amazon.JSII.JsonModel.Spec;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;

namespace Amazon.JSII.JsonModel.Converters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
using Amazon.JSII.JsonModel.Spec;
using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Amazon.JSII.JsonModel.Converters
{
class TypeDictionaryConverter : JsonConverter
internal sealed class TypeDictionaryConverter : JsonConverter
{
public override bool CanRead => true;

public override bool CanWrite => false;

public override bool CanConvert(System.Type objectType)
public override bool CanConvert(Type objectType)
{
throw new NotImplementedException();
}

public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue, JsonSerializer serializer)
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JObject untypedDictionary = JObject.Load(reader);
var untypedDictionary = JObject.Load(reader);

return untypedDictionary.Properties().ToDictionary(p => p.Name, p => Util.ConvertToDerivedType(p.Value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Amazon.JSII.JsonModel.Converters
{
static class Util
internal static class Util
{
internal static Spec.Type ConvertToDerivedType(JToken token)
{
Expand All @@ -14,27 +14,18 @@ internal static Spec.Type ConvertToDerivedType(JToken token)
throw new ArgumentException($"Unexpected token type: {token.Type}", nameof(token));
}

if (token["kind"] is JToken kindToken)
{
TypeKind kind = kindToken.ToObject<TypeKind>();

switch (kind)
{
case TypeKind.Enum:
return token.ToObject<EnumType>();

case TypeKind.Class:
return token.ToObject<ClassType>();

case TypeKind.Interface:
return token.ToObject<InterfaceType>();
if (!(token["kind"] is {} kindToken))
throw new ArgumentException($"Unexpected child token: '{token["kind"]}'", nameof(token));

var kind = kindToken.ToObject<TypeKind>();

default:
throw new ArgumentException($"Unknown kind {kind} on type {token.ToString(Formatting.Indented)}", nameof(token));
}
}

throw new ArgumentException($"Unexpected child token: '{token["kind"]}'", nameof(token));
return kind switch
{
TypeKind.Enum => (Spec.Type) token.ToObject<EnumType>(),
TypeKind.Class => token.ToObject<ClassType>(),
TypeKind.Interface => token.ToObject<InterfaceType>(),
_ => throw new ArgumentException($"Unknown kind {kind} on type {token.ToString(Formatting.Indented)}", nameof(token))
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Amazon.JSII.JsonModel
{
public abstract class JsonDictionaryBase<TKey, TValue> : IEnumerable, IEnumerable<KeyValuePair<TKey, TValue>>, IDictionary<TKey, TValue>
public abstract class JsonDictionaryBase<TKey, TValue> : IDictionary<TKey, TValue>
{
readonly IDictionary<TKey, TValue> _members = new Dictionary<TKey, TValue>();
private readonly IDictionary<TKey, TValue> _members = new Dictionary<TKey, TValue>();

#region IDictionary implementation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json;
using System;

namespace Amazon.JSII.JsonModel.Spec
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace Amazon.JSII.JsonModel.Spec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json;
using System;

namespace Amazon.JSII.JsonModel.Spec
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json;
using System;

namespace Amazon.JSII.JsonModel.Spec
{
Expand Down
Loading