Skip to content

[C#] Flatc enhancement: Expose table offsets and lengths by name #8571

@njannink

Description

@njannink

I would be great if the internal offsets would also be exposed in the generated code as named constants and that these are also actually used by the generated code. This makes things a lot more readable and gives devs the option to also reuse these consts instead of magic numbers:

current

public float3? Vertices(int j) { int o = __p.__offset(4); return o != 0 ? (float3?) (new float3()).__assign(__p.__vector(o) + j * 12, __p.bb) : null; }
public int VerticesLength { get { int o = __p.__offset(4); return o != 0 ? __p.__vector_len(o) : 0; } }
public int Tris(int j) { int o = __p.__offset(6); return o != 0 ? __p.bb.GetInt(__p.__vector(o) + j * 4) : (int) 0; }
public int TrisLength { get { int o = __p.__offset(6); return o != 0 ? __p.__vector_len(o) : 0; } }

proposed

public class TrimeshTable
{
  public const int VerticesOffset = 4;
  public const int VerticesLen = 12;
  public const int TrisOffset = 6;
  public const int TrisLen = 4;
}
public float3? Vertices(int j) { int o = __p.__offset(TrimeshTable.VerticesOffset); return o != 0 ? (float3?) (new float3()).__assign(__p.__vector(o) + j * TrimeshTable.VerticesLen, __p.bb) : null; }
public int VerticesLength { get { int o = __p.__offset(TrimeshTable.VerticesOffset); return o != 0 ? __p.__vector_len(o) : 0; } }
public int Tris(int j) { int o = __p.__offset(TrimeshTable.TrisOffset); return o != 0 ? __p.bb.GetInt(__p.__vector(o) + j * TrimeshTable.TrisLen) : (int) 0; }
public int TrisLength { get { int o = __p.__offset(TrimeshTable.TrisOffset); return o != 0 ? __p.__vector_len(o) : 0; } }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions