Fixed direction parsing, added "around" direction

This commit is contained in:
RogueException
2016-06-17 22:13:20 -03:00
parent 8df88b1bdf
commit e406ff4c5c
3 changed files with 51 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
public enum Direction
{
Before,
After
After,
Around
}
}

View File

@@ -0,0 +1,47 @@
using Newtonsoft.Json;
using System;
namespace Discord.Net.Converters
{
public class DirectionConverter : JsonConverter
{
public static readonly DirectionConverter Instance = new DirectionConverter();
public override bool CanConvert(Type objectType) => true;
public override bool CanRead => true;
public override bool CanWrite => true;
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
switch ((string)reader.Value)
{
case "before":
return Direction.Before;
case "after":
return Direction.After;
case "around":
return Direction.Around;
default:
throw new JsonSerializationException("Unknown direction");
}
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
switch ((Direction)value)
{
case Direction.Before:
writer.WriteValue("before");
break;
case Direction.After:
writer.WriteValue("after");
break;
case Direction.Around:
writer.WriteValue("around");
break;
default:
throw new JsonSerializationException("Invalid direction");
}
}
}
}

View File

@@ -43,6 +43,8 @@ namespace Discord.Net.Converters
converter = PermissionTargetConverter.Instance;
else if (type == typeof(UserStatus))
converter = UserStatusConverter.Instance;
else if (type == typeof(Direction))
converter = DirectionConverter.Instance;
//Entities
if (typeInfo.ImplementedInterfaces.Any(x => x == typeof(IEntity<ulong>)))