Browse Source

Support strings when parsing numbers

voice-allocs
RogueException 7 years ago
parent
commit
81f35a6082
3 changed files with 22 additions and 22 deletions
  1. +6
    -6
      src/Discord.Net.Serialization/Json/Converters/Primitives.Float.cs
  2. +8
    -8
      src/Discord.Net.Serialization/Json/Converters/Primitives.Signed.cs
  3. +8
    -8
      src/Discord.Net.Serialization/Json/Converters/Primitives.Unsigned.cs

+ 6
- 6
src/Discord.Net.Serialization/Json/Converters/Primitives.Float.cs View File

@@ -8,8 +8,8 @@ namespace Discord.Serialization.Json.Converters
{
if (isTopLevel)
reader.Read();
if (reader.ValueType != JsonValueType.Number)
throw new SerializationException("Bad input, expected Number");
if (reader.ValueType != JsonValueType.Number && reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected Number or String");
return reader.ParseSingle();
}
public void Write(PropertyMap map, JsonWriter writer, float value, bool isTopLevel)
@@ -27,8 +27,8 @@ namespace Discord.Serialization.Json.Converters
{
if (isTopLevel)
reader.Read();
if (reader.ValueType != JsonValueType.Number)
throw new SerializationException("Bad input, expected Number");
if (reader.ValueType != JsonValueType.Number && reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected Number or String");
return reader.ParseDouble();
}
public void Write(PropertyMap map, JsonWriter writer, double value, bool isTopLevel)
@@ -46,8 +46,8 @@ namespace Discord.Serialization.Json.Converters
{
if (isTopLevel)
reader.Read();
if (reader.ValueType != JsonValueType.Number)
throw new SerializationException("Bad input, expected Number");
if (reader.ValueType != JsonValueType.Number && reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected Number or String");
return reader.ParseDecimal();
}
public void Write(PropertyMap map, JsonWriter writer, decimal value, bool isTopLevel)


+ 8
- 8
src/Discord.Net.Serialization/Json/Converters/Primitives.Signed.cs View File

@@ -8,8 +8,8 @@ namespace Discord.Serialization.Json.Converters
{
if (isTopLevel)
reader.Read();
if (reader.ValueType != JsonValueType.Number)
throw new SerializationException("Bad input, expected Number");
if (reader.ValueType != JsonValueType.Number && reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected Number or String");
return reader.ParseInt8();
}
public void Write(PropertyMap map, JsonWriter writer, sbyte value, bool isTopLevel)
@@ -27,8 +27,8 @@ namespace Discord.Serialization.Json.Converters
{
if (isTopLevel)
reader.Read();
if (reader.ValueType != JsonValueType.Number)
throw new SerializationException("Bad input, expected Number");
if (reader.ValueType != JsonValueType.Number && reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected Number or String");
return reader.ParseInt16();
}
public void Write(PropertyMap map, JsonWriter writer, short value, bool isTopLevel)
@@ -46,8 +46,8 @@ namespace Discord.Serialization.Json.Converters
{
if (isTopLevel)
reader.Read();
if (reader.ValueType != JsonValueType.Number)
throw new SerializationException("Bad input, expected Number");
if (reader.ValueType != JsonValueType.Number && reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected Number or String");
return reader.ParseInt32();
}
public void Write(PropertyMap map, JsonWriter writer, int value, bool isTopLevel)
@@ -65,8 +65,8 @@ namespace Discord.Serialization.Json.Converters
{
if (isTopLevel)
reader.Read();
if (reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected String");
if (reader.ValueType != JsonValueType.Number && reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected Number or String");
return reader.ParseInt64();
}
public void Write(PropertyMap map, JsonWriter writer, long value, bool isTopLevel)


+ 8
- 8
src/Discord.Net.Serialization/Json/Converters/Primitives.Unsigned.cs View File

@@ -8,8 +8,8 @@ namespace Discord.Serialization.Json.Converters
{
if (isTopLevel)
reader.Read();
if (reader.ValueType != JsonValueType.Number)
throw new SerializationException("Bad input, expected Number");
if (reader.ValueType != JsonValueType.Number && reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected Number or String");
return reader.ParseUInt8();
}
public void Write(PropertyMap map, JsonWriter writer, byte value, bool isTopLevel)
@@ -27,8 +27,8 @@ namespace Discord.Serialization.Json.Converters
{
if (isTopLevel)
reader.Read();
if (reader.ValueType != JsonValueType.Number)
throw new SerializationException("Bad input, expected Number");
if (reader.ValueType != JsonValueType.Number && reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected Number or String");
return reader.ParseUInt16();
}
public void Write(PropertyMap map, JsonWriter writer, ushort value, bool isTopLevel)
@@ -46,8 +46,8 @@ namespace Discord.Serialization.Json.Converters
{
if (isTopLevel)
reader.Read();
if (reader.ValueType != JsonValueType.Number)
throw new SerializationException("Bad input, expected Number");
if (reader.ValueType != JsonValueType.Number && reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected Number or String");
return reader.ParseUInt32();
}
public void Write(PropertyMap map, JsonWriter writer, uint value, bool isTopLevel)
@@ -65,8 +65,8 @@ namespace Discord.Serialization.Json.Converters
{
if (isTopLevel)
reader.Read();
if (reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected String");
if (reader.ValueType != JsonValueType.Number && reader.ValueType != JsonValueType.String)
throw new SerializationException("Bad input, expected Number or String");
return reader.ParseUInt64();
}
public void Write(PropertyMap map, JsonWriter writer, ulong value, bool isTopLevel)


Loading…
Cancel
Save