Interface ICStructMapped<TSelf>
- Namespace
- CStructSharp
- Assembly
- CStructSharp.dll
A class that maps to and from a layout composite without reflection: ReadFrom(StructValue) builds an
instance from a parsed StructValue and WriteTo(TSelf, StructValue) fills a StructValue
of the layout's shape from an instance. The [CStructMapped] source generator writes both members for a
partial class; a class may also implement them by hand. Register<T>() makes
the type known to ReadValue<T>(Stream, string?, IReadOnlyDictionary<string, int>?, ReadOptions?),
Get<T>(string), and the write operations. Register from a module initializer
([ModuleInitializer] internal static void Register() => MappedTypes.Register<Point>();), as
generated code does: a module initializer runs before any other code in the assembly on every runtime,
Native AOT included, whereas a static constructor that nothing else triggers is removed by the AOT compiler.
public interface ICStructMapped<TSelf> where TSelf : ICStructMapped<TSelf>
Type Parameters
TSelfThe implementing class.
Methods
ReadFrom(StructValue)
Creates an instance from the members of source (converted with the Get<T>(string) rules).
public static abstract TSelf ReadFrom(StructValue source)
Parameters
sourceStructValueThe parsed composite.
Returns
- TSelf
The mapped instance.
Exceptions
- CStructReadException
A member is missing or cannot be converted.
WriteTo(TSelf, StructValue)
Stores the instance's members into target, which the writer created with the layout composite's shape.
public static abstract void WriteTo(TSelf value, StructValue target)
Parameters
valueTSelfThe instance to write.
targetStructValueThe struct value to fill; members are set by their layout names.