-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ragath
authored and
Ragath
committed
Jan 15, 2023
1 parent
75daee1
commit 97fb296
Showing
8 changed files
with
37 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace TiledLib; | ||
|
||
public class JsonStringConverter : JsonConverter<string> | ||
{ | ||
public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return reader.TokenType switch | ||
{ | ||
JsonTokenType.Number => reader.GetDecimal().ToString(), | ||
JsonTokenType.String => reader.GetString(), | ||
JsonTokenType.True or JsonTokenType.False => reader.GetBoolean().ToString(), | ||
_ => reader.GetString(), | ||
}; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) => throw new NotImplementedException(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,31 @@ | ||
| ||
|
||
namespace TiledLib; | ||
namespace TiledLib; | ||
|
||
/// <summary> | ||
/// Supports legacy property syntax | ||
/// </summary> | ||
public class PropertiesConverter : JsonConverter<Dictionary<string, string>> | ||
{ | ||
protected class Property | ||
{ | ||
public string Name { get; set; } | ||
public string Type { get; set; } | ||
[JsonConverter(typeof(JsonStringConverter))] | ||
public string Value { get; set; } | ||
} | ||
|
||
public override Dictionary<string, string> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType == JsonTokenType.StartArray) | ||
return JsonSerializer.Deserialize<Property[]>(ref reader).ToDictionary(key => key.Name, value => value.Value); | ||
{ | ||
var result = JsonSerializer.Deserialize<Property[]>(ref reader, options).ToDictionary(key => key.Name, value => value.Value.ToString()); | ||
return result; | ||
} | ||
else | ||
return JsonSerializer.Deserialize<Dictionary<string, string>>(ref reader); | ||
return JsonSerializer.Deserialize<Dictionary<string, string>>(ref reader, options); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, Dictionary<string, string> value, JsonSerializerOptions options) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters