Replies: 3 comments 29 replies
-
For the provided example, here's something you can do today: public struct MyStruct<T> where T : struct
{
public MyStructHeader Header;
public T Value;
[StructLayout(LayoutKind.Explicit)]
public struct MyStructHeader
{
[FieldOffset(0)]
public long Type;
[FieldOffset(0)]
public ushort Id;
}
} I see at your #108063 (reply in thread) comment that the union in your actual use case is between two |
Beta Was this translation helpful? Give feedback.
-
@jkotas @AaronRobinsonMSFT I think we can remove this restriction now? We already have code to validate if the type is blittable, and it will throw another exception during type loading if it's not, so there should be no issue around GC reporting. With generic support in function pointers now I can see some use cases on this. I can make a PR for this. While DO note that this restriction comes from |
Beta Was this translation helpful? Give feedback.
-
[StructLayout(LayoutKind.Explicit)] isn't supported for generic types. I think a little bit leniency could be added here, if the field with generic type T is the last field, OR if there is no T field at all and generics is for properties and methods only.
Beta Was this translation helpful? Give feedback.
All reactions