lundi 22 août 2022

can i use reflection and source generators to read structures and make new flattened structures from them I need to flatten these structs C#

Read this using reflection.

public struct WSSort
{
  public byte OrderCount;
  
  [CustomStructSize(20)]
  public Int32[] Product;
  
  public Int32 Length;
  public Int32 Moisture;
  public Int32 Stamps;

and use source generators to flatten[the arrays] in these structures

public byte OrderCount;

[CustomStructSize(20)]
public Int32 Product1; // this has the 1st element from publicInt32[]Product;
public Int32 Product2;  // this has the 2nd element from publicInt32[]Product;
    
public Int32 Product3;
public Int32 Product4;
public Int32 Product5;
    
public Int32 Length;
public Int32 Moisture;
public Int32 Stamps;

I used custom attributes to distinguish btw the stuff to read and flatten and I was able to read the structures but was not able to write them using source generators. I can't figure out how to see the generated file or debug the source generator.





Aucun commentaire:

Enregistrer un commentaire