Skip to content

Commit

Permalink
Changing the cast to be safer as IDictionary<string, string> does not…
Browse files Browse the repository at this point in the history
… implement IDictionary
  • Loading branch information
neilcampbell committed Jun 4, 2015
1 parent d186c99 commit e669617
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections;
using System.Globalization;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace PactNet.Configuration.Json.Converters
Expand All @@ -15,15 +14,14 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
}
else
{
var dictionary = (IDictionary) value;
var dictionary = (IDictionary<string, string>) value;

writer.WriteStartObject();

foreach (DictionaryEntry entry in dictionary)
foreach (var item in dictionary)
{
var key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture);
writer.WritePropertyName(key);
serializer.Serialize(writer, entry.Value);
writer.WritePropertyName(item.Key);
serializer.Serialize(writer, item.Value);
}

writer.WriteEndObject();
Expand All @@ -42,7 +40,7 @@ public override bool CanRead

public override bool CanConvert(Type objectType)
{
return typeof(IDictionary).IsAssignableFrom(objectType);
return typeof(IDictionary<string, string>).IsAssignableFrom(objectType);
}
}
}

0 comments on commit e669617

Please sign in to comment.