Table of Contents

Class EnumValueResult

Namespace
CStructSharp.Values
Assembly
CStructSharp.dll

Represents an enum payload parsed from binary data.

public class EnumValueResult
Inheritance
EnumValueResult
Derived
Inherited Members

Examples

An enum can contain a numeric value that has no declared name. EnumValueResult keeps that value, its width, and its signedness instead of discarding information:

The unknown-value case in PreserveEnum is compiled and executed during documentation validation:

private static void PreserveEnum()
{
    var layout = new CStruct("enum state : uint32 { Known = 1 }; struct root { state value; };");
    var value = (EnumValueResult)layout.ReadValue(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }, "root.value")!;
    Equal(new BigInteger(uint.MaxValue), value.Value);
    Equal(null, value.Name);
    Equal(32, value.BitWidth);
    True(!value.IsSigned, "uint32 enum should be unsigned.");
}

Remarks

The exact numeric value and storage bits remain available even when no declared member matches. Writers validate the declaration name, width, signedness, raw bits, and optional member name before reusing this model.

Properties

BitWidth

Gets the declared backing width: 8, 16, 32, or 64 bits.

public int BitWidth { get; }

Property Value

int

Enum

Gets the enum declaration name.

public string Enum { get; }

Property Value

string

IsSigned

Gets whether the declared backing domain interprets its high bit as a sign bit.

public bool IsSigned { get; }

Property Value

bool

Name

Gets the first matching declared member name, or null for an unknown payload.

public string? Name { get; }

Property Value

string

RawBits

Gets the payload's unsigned storage bits, masked to BitWidth.

public ulong RawBits { get; }

Property Value

ulong

StorageType

Gets the canonical backing codec name, such as int16 or uint64.

public string StorageType { get; }

Property Value

string

Value

Gets the exact mathematical payload without narrowing its declared integer domain.

public BigInteger Value { get; }

Property Value

BigInteger

Methods

ToString()

Returns the declared enum name when known, otherwise the numeric value from the stream.

public override string ToString()

Returns

string

The matching member name or an invariant decimal representation of Value.