Table of Contents

Class MappedTypes

Namespace
CStructSharp
Assembly
CStructSharp.dll

The registry of classes that implement ICStructMapped<TSelf>. Registration captures the type's static mapping members as delegates once, under the generic constraint, so the read and write paths can map an instance from its Type alone - no reflection, and therefore no trimming or Native AOT conventions. Generated mappers register themselves in a module initializer; a hand-written mapper does the same, or calls Register<T>() once at startup (registering twice is harmless).

public static class MappedTypes
Inheritance
MappedTypes
Inherited Members

Methods

ConvertValue<T>(object?, string)

Converts a value the reader produced (a pointer target, a union member) to T with the rules of Get<T>.

public static T ConvertValue<T>(object? value, string member)

Parameters

value object

The value to convert.

member string

The member the value belongs to, for the failure message.

Returns

T

The converted value.

Type Parameters

T

The destination type.

Exceptions

CStructReadException

The value cannot be converted without loss.

IsMapped(Type)

Whether type was registered as a mapped class.

public static bool IsMapped(Type type)

Parameters

type Type

The type to look up.

Returns

bool

true when registered.

MemberName(StructValue, string)

Finds the layout member a mapped property maps to, for a generated mapper that did not resolve its layout at build time: the exact name, else the case-insensitive match, else the match after underscores are ignored (bit_depth for BitDepth) - the generator's rule. When no member matches, or a step finds two, it returns propertyName itself, which the following Get reports as missing, with the members that exist.

public static string MemberName(StructValue source, string propertyName)

Parameters

source StructValue

The value being mapped.

propertyName string

The mapped property's name.

Returns

string

The member name to read or write.

RegisterFixed<T>()

Registers the direct members of T, after Register<T>(). The generated module initializer of a layout-bound mapped class calls both.

public static void RegisterFixed<T>() where T : ICStructMapped<T>, ICStructFixedMapped<T>

Type Parameters

T

A mapped class that also implements ICStructFixedMapped<TSelf>.

Register<T>()

Registers T so its instances can be read and written by type.

public static void Register<T>() where T : ICStructMapped<T>

Type Parameters

T

A class implementing ICStructMapped<TSelf>.

TryReadFixed<T>(ReadOnlySpan<byte>, ulong, bool, out T)

Reads a nested mapped instance directly, for a generated direct reader: only when T has direct members generated for a struct with fingerprint - the nested struct the caller was generated against.

public static bool TryReadFixed<T>(ReadOnlySpan<byte> source, ulong fingerprint, bool trimFixedText, out T value)

Parameters

source ReadOnlySpan<byte>

The nested struct's bytes.

fingerprint ulong

The fingerprint of the nested struct in the caller's layout.

trimFixedText bool

Whether fixed-capacity text drops its trailing NUL padding.

value T

The instance when the method returns true.

Returns

bool

false when T cannot be read directly here.

Type Parameters

T

The nested mapped class.

TryWriteFixed<T>(T, Span<byte>, ulong)

Writes a nested mapped instance directly, for a generated direct writer; the counterpart of TryReadFixed<T>(ReadOnlySpan<byte>, ulong, bool, out T).

public static bool TryWriteFixed<T>(T value, Span<byte> target, ulong fingerprint)

Parameters

value T

The nested instance.

target Span<byte>

The nested struct's bytes, already zero.

fingerprint ulong

The fingerprint of the nested struct in the caller's layout.

Returns

bool

false when T cannot be written directly here.

Type Parameters

T

The nested mapped class.