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 single case-insensitive match, else the single match after underscores are ignored (bit_depth for BitDepth), else 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.

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>.