Skip to content

Improve .NET Framework Span<T>/ReadOnlySpan<T> generation #1651

@mjr4077au

Description

@mjr4077au

Is your feature request related to a problem? Please describe.
I get that .NET Framework is reaching a decade old in age, however the projects I work on require that I target a built-in runtime. Further to this, my main project is used in Windows PowerShell/PowerShell 7, so considering options like NativeAOT is not possible. What I'm finding is that setups like the below don't work on .NET Framework and are appropriately unavailable for me:

internal unsafe readonly ReadOnlySpan<winmdroot.System.Diagnostics.Debug.IMAGE_DATA_DIRECTORY> AsReadOnlySpan() => MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef(in _0), SpanLength);

Describe the solution you'd like
Something like the following should achieve the same result and would work equally on .NET Framework with System.Memory, or .NET 8/9/10:

internal unsafe readonly ReadOnlySpan<winmdroot.System.Diagnostics.Debug.IMAGE_DATA_DIRECTORY> AsReadOnlySpan() => new(Unsafe.AsPointer(ref _0), SpanLength);

I am yet to test this within my own code as an extension method, but will do so soon.

Describe alternatives you've considered
My own extension method as mentioned above, however it'd be good to have this as a first class available option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions