Add .NET Standard 2.0 target to ComputeSharp
Also switch TerraFX.Interop.Windows to shared project
このコミットが含まれているのは:
1 親
78f68f7b8c
コミット
06ce524740
66ファイル変更
+1276
-178
検索条件に一致するファイルはありません
@@ -0,0 +1,28 @@
|
||||
namespace System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// A helper type with extensions for the <see cref="Dictionary{TKey, TValue}"/> type.
|
||||
/// </summary>
|
||||
internal static class DictionaryExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Tries to remove an item from a <see cref="Dictionary{TKey, TValue}"/> instance and returns it if present.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">The type of dictionary keys.</typeparam>
|
||||
/// <typeparam name="TValue">The type of dictionary values.</typeparam>
|
||||
/// <param name="dictionary">The input <see cref="Dictionary{TKey, TValue}"/> instance.</param>
|
||||
/// <param name="key">The lookup key to use.</param>
|
||||
/// <param name="value">The resulting item, if present.</param>
|
||||
/// <returns>Whether or not an item was found with the given key.</returns>
|
||||
public static bool Remove<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, out TValue value)
|
||||
{
|
||||
if (dictionary.TryGetValue(key, out value))
|
||||
{
|
||||
_ = dictionary.Remove(key);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// A helper type with extensions for the <see cref="Queue{T}"/> type.
|
||||
/// </summary>
|
||||
internal static class QueueExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Tries to dequeue an item from the input <see cref="Queue{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items in the queue.</typeparam>
|
||||
/// <param name="queue">The input queue.</param>
|
||||
/// <param name="result">The resulting item, if any.</param>
|
||||
/// <returns>Whether or not an item was found.</returns>
|
||||
public static bool TryDequeue<T>(this Queue<T> queue, out T? result)
|
||||
{
|
||||
if (queue.Count > 0)
|
||||
{
|
||||
result = queue.Dequeue();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
result = default!;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace ComputeSharp.NetStandard.System;
|
||||
|
||||
/// <summary>
|
||||
/// A polyfill type that mirrors some methods from <see cref="global::System.Enum"/> on .NET 6.
|
||||
/// </summary>
|
||||
internal static class Enum
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the name of the input enum value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Specifies the type of the enum element.</typeparam>
|
||||
/// <param name="value">The input enum value.</param>
|
||||
/// <returns>The name of <paramref name="value"/>.</returns>
|
||||
public static string GetName<T>(T value)
|
||||
where T : unmanaged, global::System.Enum
|
||||
{
|
||||
return global::System.Enum.GetName(typeof(T), value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace ComputeSharp.NetStandard.System;
|
||||
|
||||
/// <summary>
|
||||
/// A polyfill type that mirrors some methods from <see cref="global::System.GC"/> on .NET 6.
|
||||
/// </summary>
|
||||
internal static class GC
|
||||
{
|
||||
/// <summary>
|
||||
/// Allocate an array while skipping zero-initialization if possible.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Specifies the type of the array element.</typeparam>
|
||||
/// <param name="length">Specifies the length of the array.</param>
|
||||
/// <param name="pinned">Specifies whether the allocated array must be pinned.</param>
|
||||
/// <remarks>
|
||||
/// If pinned is set to true, <typeparamref name="T"/> must not be a reference type or a type that contains object references.
|
||||
/// </remarks>
|
||||
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false)
|
||||
{
|
||||
return new T[length];
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,18 @@
|
||||
namespace System;
|
||||
|
||||
/// <summary>
|
||||
/// A polyfill type with extensions for <see cref="nint"/> and <see cref="nuint"/>.
|
||||
/// A polyfill type with extensions for <see cref="IntPtr"/> and <see cref="UIntPtr"/>.
|
||||
/// </summary>
|
||||
internal static class IntPtrExtensions
|
||||
{
|
||||
/// <inheritdoc cref="IComparable{T}.CompareTo(T?)"/>
|
||||
/// <inheritdoc cref="IComparable{T}.CompareTo(T)"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int CompareTo(this nint left, nint right)
|
||||
{
|
||||
return left.CompareTo(right);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IComparable{T}.CompareTo(T?)"/>
|
||||
/// <inheritdoc cref="IComparable{T}.CompareTo(T)"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int CompareTo(this nuint left, nuint right)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.NetStandard.System.IO;
|
||||
|
||||
/// <summary>
|
||||
/// A polyfill type that mirrors some methods from <see cref="global::System.IO.Path"/> on .NET 6.
|
||||
/// </summary>
|
||||
internal static class Path
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the extension of the given path.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The returned value is an empty <see cref="ReadOnlySpan{T}"/> if the given path does not include an extension.
|
||||
/// </remarks>
|
||||
public static ReadOnlySpan<char> GetExtension(ReadOnlySpan<char> path)
|
||||
{
|
||||
return global::System.IO.Path.GetExtension(path.ToString()).AsSpan();
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
namespace System.Runtime.CompilerServices;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates which arguments to a method involving an interpolated string handler should be passed to that handler.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
|
||||
public sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InterpolatedStringHandlerArgumentAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="argument">The name of the argument that should be passed to the handler.</param>
|
||||
/// <remarks><see langword="null"/> may be used as the name of the receiver in an instance method.</remarks>
|
||||
public InterpolatedStringHandlerArgumentAttribute(string argument) => Arguments = new string[] { argument };
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InterpolatedStringHandlerArgumentAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="arguments">The names of the arguments that should be passed to the handler.</param>
|
||||
/// <remarks><see langword="null"/> may be used as the name of the receiver in an instance method.</remarks>
|
||||
public InterpolatedStringHandlerArgumentAttribute(params string[] arguments) => Arguments = arguments;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the names of the arguments that should be passed to the handler.
|
||||
/// </summary>
|
||||
/// <remarks><see langword="null"/> may be used as the name of the receiver in an instance method.</remarks>
|
||||
public string[] Arguments { get; }
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
namespace System.Runtime.CompilerServices;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the attributed type is to be used as an interpolated string handler.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
|
||||
public sealed class InterpolatedStringHandlerAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace System.Runtime.CompilerServices;
|
||||
|
||||
/// <summary>
|
||||
/// Used to indicate to the compiler that the <c>.locals init</c>
|
||||
/// flag should not be set in method headers.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This attribute is unsafe because it may reveal uninitialized memory to
|
||||
/// the application in certain instances (e.g., reading from uninitialized
|
||||
/// stackalloc'd memory). If applied to a method directly, the attribute
|
||||
/// applies to that method and all nested functions (lambdas, local
|
||||
/// functions) below it. If applied to a type or module, it applies to all
|
||||
/// methods nested inside. This attribute is intentionally not permitted on
|
||||
/// assemblies. Use at the module level instead to apply to multiple type
|
||||
/// declarations.
|
||||
/// </remarks>
|
||||
[AttributeUsage(AttributeTargets.Module
|
||||
| AttributeTargets.Class
|
||||
| AttributeTargets.Struct
|
||||
| AttributeTargets.Interface
|
||||
| AttributeTargets.Constructor
|
||||
| AttributeTargets.Method
|
||||
| AttributeTargets.Property
|
||||
| AttributeTargets.Event, Inherited = false)]
|
||||
internal sealed class SkipLocalsInitAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -22,6 +22,17 @@ internal static class MemoryMarshal
|
||||
return ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(span);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a reference to the 0th element of <paramref name="array"/>. If the array is empty, returns a reference
|
||||
/// to where the 0th element would have been stored. Such a reference may be used for pinning but must never be dereferenced.
|
||||
/// </summary>
|
||||
/// <exception cref="NullReferenceException"><paramref name="array"/> is <see langword="null"/>.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ref T GetArrayDataReference<T>(T[] array)
|
||||
{
|
||||
return ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(array.AsSpan());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Span{T}"/> from a given reference.
|
||||
/// </summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする