Fixes bug with configurations (#236)

- [X] Changes brace style to enforced
- [X] Fixes null source with assemblies.json
- [X] Fixes bad path for missing json files

Bumps release version
This commit is contained in:
Kamron Batman 2020-09-10 23:38:06 -07:00 • committed by GitHub
parent 96465c8530
commit c3d2740983
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 27 deletions

View file

@ -44,21 +44,33 @@ namespace Server.Json
options.Converters.Add(new NullableStructSerializerFactory());
options.Converters.Add(new TypeConverterFactory());
for (var i = 0; i < converters.Length; i++) options.Converters.Add(converters[i]);
for (var i = 0; i < converters.Length; i++)
{
options.Converters.Add(converters[i]);
}
return options;
}
public static T Deserialize<T>(string filePath, JsonSerializerOptions options = null)
{
if (!File.Exists(filePath)) return default;
if (!File.Exists(filePath))
{
return default;
}
var text = File.ReadAllText(filePath, Utility.UTF8);
return JsonSerializer.Deserialize<T>(text, options ?? DefaultOptions);
}
public static void Serialize(string filePath, object value, JsonSerializerOptions options = null)
{
if (File.Exists(filePath)) File.Delete(filePath);
if (File.Exists(filePath))
{
File.Delete(filePath);
}
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
File.WriteAllText(filePath, JsonSerializer.Serialize(value, options ?? DefaultOptions));
}
@ -80,7 +92,10 @@ namespace Server.Json
public static T ToObject<T>(this JsonDocument document, JsonSerializerOptions options = null)
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}
return document.RootElement.ToObject<T>(options);
}
}