Skip to content
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

Open
sgf opened this issue Jul 19, 2024 · 3 comments
Open

Add InlineArray Auto-Gen feature support #3

sgf opened this issue Jul 19, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@sgf
Copy link

sgf commented Jul 19, 2024

because this feature is often used together with bit-field, so it would be good to put it in the same library.

@sgf sgf changed the title Add InlineArray Auto-Gen feature Add InlineArray Auto-Gen feature support Jul 19, 2024
@barncastle barncastle added the enhancement New feature or request label Jul 20, 2024
@barncastle
Copy link
Owner

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

@sgf
Copy link
Author

sgf commented Jul 21, 2024

I had a similar open source project. But I abandoned that project because your implementation is better.

https://github.com/sgf/BitX

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

}

@sgf
Copy link
Author

sgf commented Jul 21, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants