Enum GeneratedShape
- Namespace
- CStructSharp
- Assembly
- CStructSharp.dll
Chooses the C# type the generator makes of each struct and union of a layout.
public enum GeneratedShape
Fields
Auto = 2A Struct when the layout and surface qualify for one, otherwise a Class, decided for the whole layout class: nothing is reported when it does not qualify. It lets a project set one shape for every layout (
CStructSharpShape) and take the value type where there is one. The members of both shapes that consumer code can share are the scalars, text, nested values and, for a fixed array of numbers, the index,LengthandAsSpan(); code that needs more (the array type itself, thedefaultof a missing value) names its shape.Class = 0A sealed class with settable properties, the default, which every surface can generate.
Scalar = 3No type at all: a layout whose root struct holds exactly one number, enum or identifier at offset 0 generates a static
Parsethat returns that value (auint, an enum, a Guid) and, on the Reader surface,TryParse; failures, limits and constraints are the struct's. It needs the Reader or Parser surface and generates no view. Any other layout is reported as CSG015. It is for the hundreds of one-field layouts a project reads (a stored word, a magic number), each of which would otherwise cost a class and three readers.Struct = 1A struct of at most 1,024 bytes whose members are public fields. A fixed array of numbers is a generated inline array type (
InlineArrays.ByteArray4, withAsSpan(),ToArray()and an indexer) instead of aT[]. It needs the Reader or Parser surface and a layout that is fixed in size, with no union, conditional member, pointer, runtime-sized array or terminated string; anything else is reported as CSG014.
Remarks
A class is a heap object: reading one allocates it (and an array for every array member). A struct is a value that lives in the caller's variable, so a read of a layout of numbers, enums, bitfields, nested structs, text and fixed numeric arrays allocates nothing for the value itself, and the value can be kept in a collection and used across an await, which a generated view cannot.