Added converter to improve object serialization

This commit is contained in:
Florian Rappl
2025-11-08 16:38:36 +01:00
parent 758e6a41e3
commit d03458094b
3 changed files with 69 additions and 2 deletions

View File

@@ -0,0 +1,20 @@
namespace ElectronNET.API.Entities;
public class PageSize
{
private readonly string _value;
public PageSize()
{
}
private PageSize(string value) : this() => _value = value;
public double Height { get; set; }
public double Width { get; set; }
public static implicit operator string(PageSize pageSize) => pageSize?._value;
public static implicit operator PageSize(string value) => new(value);
}

View File

@@ -1,4 +1,7 @@
namespace ElectronNET.API.Entities;
using ElectronNET.Converter;
using Newtonsoft.Json;
namespace ElectronNET.API.Entities;
/// <summary>
///
@@ -30,7 +33,8 @@ public class PrintToPDFOptions
/// `A5`, `A6`, `Legal`, `Letter`, `Tabloid`, `Ledger`, or an Object containing
/// `height` and `width` in inches. Defaults to `Letter`.
/// </summary>
public object PageSize { get; set; } = "Letter";
[JsonConverter(typeof(PageSizeConverter))]
public PageSize PageSize { get; set; } = "Letter";
/// <summary>
/// Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string,