Create a gist now

Instantly share code, notes, and snippets.

Json.NET Metro Upgrade Kit
public class MetroPropertyNameResolver : DefaultContractResolver
{
protected internal override string ResolvePropertyName(string propertyName)
{
return ":::" + propertyName.ToUpper() + ":::";
}
}
public class MetroStringConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteValue(":::" + value.ToString().ToUpper() + ":::");
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return existingValue;
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof (string);
}
}
public class MetroColorConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
Color color = (Color) value;
Color fixedColor = (color == Color.White || color == Color.Black) ? color : Color.Gray;
writer.WriteValue(":::" + fixedColor.ToKnownColor().ToString().ToUpper() + ":::");
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Enum.Parse(typeof (Color), reader.Value.ToString());
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof (Color);
}
}
@XiXora

Thank you so much.
It is now much easier to build my Metro applications!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment