Variant

Energy.Base.Variant provides a flexible value container that can hold a single value and expose it as different primitive types. It is useful for dynamic data, weak typing, or interop scenarios.

Union

Energy.Base.Variant.Union stores a single object and exposes it as different types. It does not reallocate the underlying value; it simply casts or converts on access.

Energy.Base.Variant.Union union = new Energy.Base.Variant.Union();
union.Value = "123";

Console.WriteLine(union.String); // "123"
Console.WriteLine(union.SInt32); // 123
Console.WriteLine(union.Bool);   // true

Available accessors:

  • Bool, UInt8, SInt8, UInt16, SInt16, UInt32, SInt32, UInt64, SInt64

  • Char, Float, Double, Decimal, DateTime, TimeSpan

  • String, Array, Object

Value

Energy.Base.Variant.Value wraps a Union with a tracked type.

Energy.Base.Variant.Value value = new Energy.Base.Variant.Value("Hello");
Console.WriteLine(value.Object);
Console.WriteLine(value.Type);

Variable

Energy.Base.Variant.Variable is a named value that can be used for dynamic variables.

Dictionary

Energy.Base.Variant.Dictionary is a string-keyed dictionary of Energy.Base.Variant.Value objects.

UnionExplicit

Energy.Base.Variant.UnionExplicit is an overlapping struct that uses StructLayout.Explicit to share memory between different value types.

Note: This is intended for advanced interop scenarios.

See also

  • base-cast for safe type conversions.