© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•6mo ago•
23 replies
peppy

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

Given several inline array types of
byte
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
[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>
Span<byte>
like such:
public static class Extensions {
    public static string decode_name(this Span<byte> name) {
        // ...
    }
}
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
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(); 
    }
}
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ array of methods
C#CC# / help
17mo ago
Inline array of struct assignment
C#CC# / help
3y ago
✅ Extension Methods
C#CC# / help
2y ago
Extension Methods
C#CC# / help
2y ago