feat: Adds GUID support for codegen (#1251)
This commit is contained in:
parent
58acfcabad
commit
32c15f214b
4 changed files with 7 additions and 14 deletions
|
|
@ -21,16 +21,9 @@ namespace Server.Json;
|
|||
|
||||
public class GuidConverter : JsonConverter<Guid>
|
||||
{
|
||||
public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (Guid.TryParse(reader.GetString()!, out var guid))
|
||||
{
|
||||
return guid;
|
||||
}
|
||||
public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.GetGuid();
|
||||
|
||||
throw new JsonException("Guid must be in the correct format");
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options)
|
||||
=> writer.WriteStringValue(value.ToString());
|
||||
public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options) =>
|
||||
writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue