CSharp · Console
using System;
public class Program
{
public enum LengthUnitTypes
{
None,
m,
cm,
mm,
um,
@in,
ft,
km,
mi
}
public struct Length{
public Length()
{
}
//[System.Text.Json.Serialization.JsonConstructorAttribute]
public Length(double value, LengthUnitTypes unit)
{
Value = value;
Unit = unit;
}
public double Value { get; set; } = 0;
public LengthUnitTypes Unit { get; set; } = LengthUnitTypes.None;
}
public static void Main()
{
var l = new Length();
var json = System.Text.Json.JsonSerializer.Serialize(l);
Console.WriteLine(json);
l = System.Text.Json.JsonSerializer.Deserialize<Length>(json);
Console.WriteLine("Hello World");
}
}