Class CStructLayoutAttribute
- Namespace
- CStructSharp
- Assembly
- CStructSharp.dll
Asks the CStructSharp source generator to turn a layout into C# at compile time: one class per struct and
union, an enum per layout enum, and straight-line Parse, Serialize, Update, and
ResolveAddress methods on the attributed static partial class, with the same results and the
same diagnostics as CStruct produces for the same definition and options.
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed class CStructLayoutAttribute : Attribute
- Inheritance
-
CStructLayoutAttribute
- Inherited Members
Remarks
The layout is the constructor argument or, with File, a .cstruct file the project lists
as an AdditionalFiles item. The other properties mirror the CStruct constructor and
CStructCompilationOptions.
Constructors
CStructLayoutAttribute()
Generates from the file named by File.
public CStructLayoutAttribute()
CStructLayoutAttribute(string)
Generates from layout text.
public CStructLayoutAttribute(string definition)
Parameters
definitionstringThe Portable v1 layout source.
Properties
Aligned
Gets or sets whether the portable composite-alignment rules apply.
public bool Aligned { get; set; }
Property Value
BitfieldAllocation
Gets or sets which end of a storage unit bitfields are allocated from.
public BitfieldAllocation BitfieldAllocation { get; set; }
Property Value
BitfieldPacking
Gets or sets how bitfields pack into storage units.
public BitfieldPacking BitfieldPacking { get; set; }
Property Value
CLongWidth
Gets or sets the width of C long in bits; 0 means the library default (64).
public int CLongWidth { get; set; }
Property Value
Codecs
Gets or sets the custom codecs the layout uses, one declaration per codec: "name" for a
variable-length codec, "name:size" for a fixed size in bytes, "name:size:alignment" to also
give the alignment ("name:*:alignment" for a variable-length one). The generator places fields with
these facts; the class supplies the matching ICustomCodec instances, in the same order,
from its static partial IReadOnlyList<ICustomCodec> CreateCodecs() method.
public string[]? Codecs { get; set; }
Property Value
- string[]
DefaultEnumStorage
Gets or sets the storage type of an enum declared without one (enum kind { ... }); null means the library default.
public string? DefaultEnumStorage { get; set; }
Property Value
Defined
Gets or sets the preprocessor symbols defined for the layout.
public string[]? Defined { get; set; }
Property Value
- string[]
Definition
Gets the layout text, when it was given inline.
public string? Definition { get; }
Property Value
File
Gets or sets the path of a .cstruct additional file, relative to the project, holding the layout text.
public string? File { get; set; }
Property Value
KeepNames
Gets or sets whether generated names keep the layout's spelling instead of becoming PascalCase.
public bool KeepNames { get; set; }
Property Value
LittleEndian
Gets or sets whether neutral values are little-endian.
public bool LittleEndian { get; set; }
Property Value
PointerSize
Gets or sets the pointer width in bytes (1, 2, 4, or 8).
public int PointerSize { get; set; }
Property Value
Root
Gets or sets the declaration the plain Parse/Serialize methods use; the default is the first struct.
public string? Root { get; set; }
Property Value
Views
Gets or sets whether a zero-allocation ref struct view is generated per composite.
public bool Views { get; set; }