flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

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

Open njannink opened this issue 1 year ago • 3 comments

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; } }

njannink avatar Apr 04 '25 15:04 njannink

Maybe even dictionary access by name would be very helpfull

njannink avatar Apr 04 '25 15:04 njannink

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Oct 03 '25 20:10 github-actions[bot]

this enhancement request is still valid. Magic numbers are always bad design

njannink avatar Oct 05 '25 16:10 njannink