Class ValueBox
- Namespace
- The.Persistence
- Assembly
- Instagile.dll
ValueBox wraps an object which is one of the finite The.Values types.
[MessagePackObject(false)]
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$")]
[Union(0, typeof(BoolBox))]
[JsonDerivedType(typeof(BoolBox), 0)]
[Union(1, typeof(ByteBox))]
[JsonDerivedType(typeof(ByteBox), 1)]
[Union(2, typeof(DateBox))]
[JsonDerivedType(typeof(DateBox), 2)]
[Union(3, typeof(DateTimeBox))]
[JsonDerivedType(typeof(DateTimeBox), 3)]
[Union(4, typeof(DecBox))]
[JsonDerivedType(typeof(DecBox), 4)]
[Union(5, typeof(DoubleBox))]
[JsonDerivedType(typeof(DoubleBox), 5)]
[Union(6, typeof(GuidBox))]
[JsonDerivedType(typeof(GuidBox), 6)]
[Union(7, typeof(InstantBox))]
[JsonDerivedType(typeof(InstantBox), 7)]
[Union(8, typeof(IntBox))]
[JsonDerivedType(typeof(IntBox), 8)]
[Union(9, typeof(LongBox))]
[JsonDerivedType(typeof(LongBox), 9)]
[Union(10, typeof(StringBox))]
[JsonDerivedType(typeof(StringBox), 10)]
[Union(11, typeof(TimeBox))]
[JsonDerivedType(typeof(TimeBox), 11)]
[Union(12, typeof(PeriodBox))]
[JsonDerivedType(typeof(PeriodBox), 12)]
[Union(13, typeof(VersionBox))]
[JsonDerivedType(typeof(VersionBox), 13)]
public abstract class ValueBox : IComparable
- Inheritance
-
ValueBox
- Implements
- Derived
- Inherited Members
Remarks
Many serialisation formats are based roughly on the JSON primitives: object, array, string, number, boolean. This model is flexible but it has a few problems for working with dynamic data:
- can't differentiate between numeric types (int vs long, float vs double vs decimal, sometimes all of the above are combined)
- no encoding for composite value types (guid, timespan, or most generally: byte array)
- dates are encoded in many different incompatible ways, even by .NET itself
- some serialisers can't handle too much dynamism, e.g. object-which-might-be-null-or-primitive
To avoid these problems, we replace CLR boxing with an explicit discriminated union.
Methods
Box(object?)
public static ValueBox? Box(object? o)
Parameters
oobject
Returns
CompareTo(object?)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public abstract int CompareTo(object? other)
Parameters
otherobject
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes objin the sort order.Zero This instance occurs in the same position in the sort order as obj.Greater than zero This instance follows objin the sort order.
Exceptions
- ArgumentException
objis not the same type as this instance.
Type(Type)
public static TypeBox Type(Type type)
Parameters
typeType
Returns
Unbox(ValueBox?)
public static object? Unbox(ValueBox? b)
Parameters
bValueBox