-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add InlineArray Auto-Gen feature support #3
Comments
Great feature idea! I've not had much exposure to Inline Arrays but this shouldn't be too difficult to implement In terms of implementation; do you have an example use case for this? I'm wondering if this should support all integral inline arrays or just byte ones |
I had a similar open source project. But I abandoned that project because your implementation is better. public struct MyStruct{
public byte Field1;
public byte Field2;
public short Field3;
}
public struct TestStruct1
{
public byte BF1;
public int BF2;
[InlineLen(3)]
public MyStruct buff; //InlineLen is a custome Attribute by your library maybe u can chose a better name
}
//generated maybe like :
[System.Runtime.CompilerServices.InlineArray(3)]
public struct MyStruct_3
{
private MyStruct _element0;
public const int Length = 3;
//not need to define ,because InlineArray has been implemented
//public Span<MyStruct> GetSpan() => MemoryMarshal.CreateSpan(ref Unsafe.As<MyStruct>(ref this),3);
//public MyStruct this[int index] {{ get => this[index]; set => this[index] = value; }}
}
|
This feature is mainly used to allow custom structures to support fixed buffers, but the official implementation is not elegant and practical. Therefore, it is necessary to combine it with a source code generator to make the code writing process simpler. Of course, the frequency of use of this feature itself is not very high. |
because this feature is often used together with bit-field, so it would be good to put it in the same library.
The text was updated successfully, but these errors were encountered: