C#C
C#4mo ago
peppy

Interaction of 'first class spans' with inline array types/Extension methods over inline array types

Given several inline array types of byte of various lengths used to model certain fixed size buffers:
[InlineArray(40)]
public struct ByteArray40 {
    private byte _b;
}
[InlineArray(20)]
public struct ByteArray20 {
    private byte _b;
}
// many, many others

would it be possible, with the upcoming 'first class spans' (https://github.com/dotnet/csharplang/issues/8714), to write an extension method over Span<byte> like such:
public static class Extensions {
    public static string decode_name(this Span<byte> name) {
        // ...
    }
}

and then have that extension appear over all inline array types of byte as such:
public struct CHRDATA {
    public ByteArray20 chr_name;
    public ByteArray40 chr_name_extended;

    public void test() {
        string str_chr_name          = chr_name.decode_name();
        string str_chr_name_extended = chr_name_extended.decode_name(); 
    }
}

or is that not covered by that proposal? If not, can this (defining a single extension method for any inline array of a given primitive) be achieved in some other way?
Was this page helpful?