1

I would like to know if it is possible to add attributes to a class at compile time using Afterthought. I know this is possible with PostSharp but for Afterthought, I can only see attribute ammendments on properties. I would like to do something like this.

[AddStructLayout]
class Foo
{
    float A;
    float B;
}

should generate

[Struct;StructLayout(Explicit)]
class Foo
{
    [FieldOffset(0)]
    float A;
    [FieldOffset(16)]
    float B;
}

My use case is to add the StructLayout attribute on the class and FieldOffset attributes to the fields in my class to enforce the memory layout in a specific way. The exact layout rules are determined by the aspect.

Thanks Johan

Johan
  • 660
  • 1
  • 6
  • 13

0 Answers0