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
valueobjectThe value to convert.
memberstringThe member the value belongs to, for the failure message.
Returns
- T
The converted value.
Type Parameters
TThe 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
typeTypeThe type to look up.
Returns
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
sourceStructValueThe value being mapped.
propertyNamestringThe 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
TA 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
TA 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
sourceReadOnlySpan<byte>The nested struct's bytes.
fingerprintulongThe fingerprint of the nested struct in the caller's layout.
trimFixedTextboolWhether fixed-capacity text drops its trailing NUL padding.
valueTThe instance when the method returns true.
Returns
Type Parameters
TThe 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
valueTThe nested instance.
targetSpan<byte>The nested struct's bytes, already zero.
fingerprintulongThe fingerprint of the nested struct in the caller's layout.
Returns
Type Parameters
TThe nested mapped class.