Fixed direction parsing, added "around" direction
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
public enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
Before,
|
Before,
|
||||||
After
|
After,
|
||||||
|
Around
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
47
src/Discord.Net/Net/Converters/DirectionConverter.cs
Normal file
47
src/Discord.Net/Net/Converters/DirectionConverter.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,6 +43,8 @@ namespace Discord.Net.Converters
|
|||||||
converter = PermissionTargetConverter.Instance;
|
converter = PermissionTargetConverter.Instance;
|
||||||
else if (type == typeof(UserStatus))
|
else if (type == typeof(UserStatus))
|
||||||
converter = UserStatusConverter.Instance;
|
converter = UserStatusConverter.Instance;
|
||||||
|
else if (type == typeof(Direction))
|
||||||
|
converter = DirectionConverter.Instance;
|
||||||
|
|
||||||
//Entities
|
//Entities
|
||||||
if (typeInfo.ImplementedInterfaces.Any(x => x == typeof(IEntity<ulong>)))
|
if (typeInfo.ImplementedInterfaces.Any(x => x == typeof(IEntity<ulong>)))
|
||||||
|
|||||||
Reference in New Issue
Block a user