mirror of
https://github.com/SamueleLorefice/ComfySharp
synced 2026-01-15 03:35:48 +00:00
Added JSONserialization options (because this is not a default in 2023, for some reasons, well)
This commit is contained in:
@@ -8,7 +8,7 @@ namespace ComfySharp;
|
|||||||
public class ConversionSettings {
|
public class ConversionSettings {
|
||||||
[DataMember(IsRequired = true)] public List<string> EnumConvertAsString = new();
|
[DataMember(IsRequired = true)] public List<string> EnumConvertAsString = new();
|
||||||
[DataMember(IsRequired = true)] public List<string> EnumConvertAsBool = new();
|
[DataMember(IsRequired = true)] public List<string> EnumConvertAsBool = new();
|
||||||
|
static JsonSerializerOptions jsonOpt = new() { WriteIndented = true, IncludeFields = true };
|
||||||
public static ConversionSettings FromFile(string path) {
|
public static ConversionSettings FromFile(string path) {
|
||||||
if (!File.Exists(path)) throw new FileNotFoundException("Could not find settings file", path);
|
if (!File.Exists(path)) throw new FileNotFoundException("Could not find settings file", path);
|
||||||
string json = File.ReadAllText(path);
|
string json = File.ReadAllText(path);
|
||||||
@@ -17,7 +17,7 @@ public class ConversionSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ConversionSettings FromJson(string json) {
|
public static ConversionSettings FromJson(string json) {
|
||||||
ConversionSettings? settings = JsonSerializer.Deserialize<ConversionSettings>(json);
|
ConversionSettings? settings = JsonSerializer.Deserialize<ConversionSettings>(json, jsonOpt);
|
||||||
if (settings is null) throw new NullReferenceException("Could not deserialize settings file");
|
if (settings is null) throw new NullReferenceException("Could not deserialize settings file");
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,6 @@ public class ConversionSettings {
|
|||||||
|
|
||||||
public void Save(string path) => File.WriteAllText(path, ToJson());
|
public void Save(string path) => File.WriteAllText(path, ToJson());
|
||||||
|
|
||||||
public string ToJson() => JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true, IncludeFields = true });
|
public string ToJson() => JsonSerializer.Serialize(this, jsonOpt);
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user