-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace <%= namespace%>; | ||
|
||
public static class Constants | ||
{ | ||
public const string DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ssK"; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace <%= namespace%>; | ||
|
||
public class DateTimeSerializer : JsonConverter<DateTime> | ||
{ | ||
public override DateTime Read( | ||
ref Utf8JsonReader reader, | ||
System.Type typeToConvert, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
return DateTime.ParseExact(reader.GetString()!, Constants.DateTimeFormat, null); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value.ToString(Constants.DateTimeFormat)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Text.Json; | ||
|
||
namespace <%= namespace%>; | ||
|
||
public static class JsonOptions | ||
{ | ||
public static readonly JsonSerializerOptions JsonSerializerOptions; | ||
|
||
static JsonOptions() | ||
{ | ||
JsonSerializerOptions = new JsonSerializerOptions | ||
{ | ||
Converters = { new DateTimeSerializer() }, | ||
WriteIndented = true | ||
}; | ||
} | ||
} | ||
|
||
public static class JsonUtils | ||
{ | ||
public static string Serialize<T>(T obj) | ||
{ | ||
return JsonSerializer.Serialize(obj, JsonOptions.JsonSerializerOptions); | ||
} | ||
|
||
public static T Deserialize<T>(string json) | ||
{ | ||
return JsonSerializer.Deserialize<T>(json, JsonOptions.JsonSerializerOptions)!; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.3 | ||
0.1.4 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.