protected virtual void VisitStruct(Definitions.StructDefinition @struct) { foreach (var field in @struct.Fields) { VisitStructField(@struct, field); } }
public void WriteStruct(Definitions.StructDefinition @struct) { WriteSummary(@struct); if (@struct.Attrs.Count > 0) { Writer.WriteLine($"[{string.Join(", ", @struct.Attrs)}]"); } Writer.WriteLine("[StructLayout(LayoutKind.Sequential)]"); using (BeginBlock($"unsafe public struct {@struct.CSharpName} ")) { foreach (var field in @struct.Fields) { WriteSummary(field); foreach (var attr in field.Attrs) { Writer.WriteLine($"[{attr}]"); } if (field.IsObsolete) { Writer.WriteLine($@"[Obsolete(@""{field.ObsoleteMessage?.Replace("\"", "\"\"") ?? string.Empty}"")]"); } if (field.FixedSize == 0) { Writer.WriteLine($"public {field.FieldType.CSharpName} {field.CSharpName};"); } else { Writer.WriteLine($"public fixed {field.FieldType.CSharpName} {field.CSharpName}[{field.FixedSize}];"); } } } }
protected virtual void VisitStructField(Definitions.StructDefinition @struct, Definitions.StructField field) { if (field.FieldType.Modifies.Count == 0 && Processor.UnitsMap.TryGetValue(field.FieldType.Name, out var def)) { if (def is Definitions.FixedArrayDefinition fixedArray && fixedArray.IsPrimitive) { field.FieldType = fixedArray.ElementType; field.FixedSize = fixedArray.Size; } } }
protected virtual void RenameStruct(Definitions.StructDefinition @struct) { if (@struct.CSharpName != null) { return; } @struct.CSharpName = @struct.Name; foreach (var field in @struct.Fields) { RenameType(field.FieldType); RenameStructField(@struct, field); } }
protected virtual void RenameStructField(Definitions.StructDefinition @struct, Definitions.StructField field) { field.CSharpName = NamedTool.ToCamelNamed(field.Name); }