Skip to content

Move Span.NonPortableCast to MemoryMarshal and rename to Cast #24689

Description

@ahsonkhan

From https://github.com/dotnet/corefx/issues/26139#issuecomment-358090527:

Move and rename NonPortableCast to MemoryMarshal.Cast

Current API:

namespace System
{
    public static partial class MemoryExtensions
    {
        public static ReadOnlySpan<TTo> NonPortableCast<TFrom, TTo>(this ReadOnlySpan<TFrom> source) where TFrom : struct where TTo : struct { throw null; }
        public static Span<TTo> NonPortableCast<TFrom, TTo>(this Span<TFrom> source) where TFrom : struct where TTo : struct { throw null; }
    }
}

Proposed API:

namespace System.Runtime.InteropServices
{
    public static partial class MemoryMarshal
    {
        public static bool TryCast<TFrom, TTo>(ReadOnlySpan<TFrom> source, out ReadOnlySpan<TTo> output) where TFrom : struct where TTo : struct { throw null; }
        public static bool TryCast<TFrom, TTo>(Span<TFrom> source, out Span<TTo> output) where TFrom : struct where TTo : struct { throw null; }
    }
}

Edit: Removed this
Edit by @ianhays: Changed Cast to TryCast per discussion

cc @jkotas, @KrzysztofCwalina

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Memorygood first issueIssue should be easy to implement, good for first-time contributors

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions