Split from https://github.com/dotnet/corefx/issues/26368
namespace System
{
public static partial class MemoryExtensions
{
public static bool TryCast<TFrom, TTo>(this ReadOnlySpan<TFrom> source, out ReadOnlySpan<TTo> output) where TFrom : struct where TTo : struct;
public static bool TryCast<TFrom, TTo>(this Span<TFrom> source, out Span<TTo> output) where TFrom : struct where TTo : struct;
}
}
We should add some TryCast extension methods that behave similar to the NonPortableCast functions but that include checking beforehand to make sure the operation will be succeed with a usable Span result. To do this, they will need a structure somewhat like this:
if (Platform detect intel)
{
// do NonPortableCast
// return true;
}
else
{
// check the alignment manually.
if ( we're already aligned)
{
// do NonPortableCast
return true;
}
else
{
//do nothing
return false;
}
}
Split from https://github.com/dotnet/corefx/issues/26368
We should add some TryCast extension methods that behave similar to the NonPortableCast functions but that include checking beforehand to make sure the operation will be succeed with a usable Span result. To do this, they will need a structure somewhat like this: