Generator: Simplify bindings and use StdCall instead of if/else NET6_0_OR_GREATER + more D3D11 bindings.

This commit is contained in:
Amer Koleci
2022-09-07 14:00:03 +02:00
parent 234cb9b5e5
commit 32aa01c8e4
10 changed files with 303 additions and 17140 deletions

View File

@@ -13,7 +13,7 @@ namespace Win32;
/// <typeparam name="T">The type to wrap in the current <see cref="ComPtr{T}"/> instance.</typeparam>
/// <remarks>While this type is not marked as <see langword="ref"/> so that it can also be used in fields, make sure to keep the reference counts properly tracked if you do store <see cref="ComPtr{T}"/> instances on the heap.</remarks>
public unsafe struct ComPtr<T> : IDisposable
where T : unmanaged, IUnknown.Interface
where T : unmanaged
{
/// <summary>The raw pointer to a COM object, if existing.</summary>
private T* ptr_;
@@ -52,9 +52,9 @@ public unsafe struct ComPtr<T> : IDisposable
/// <returns>The result of <see cref="IUnknown.QueryInterface"/> for the target type <typeparamref name="U"/>.</returns>
/// <remarks>This method will automatically release the target COM object pointed to by <paramref name="p"/>, if any.</remarks>
public readonly HResult As<U>(ComPtr<U>* p)
where U : unmanaged, IUnknown.Interface
where U : unmanaged
{
return ptr_->QueryInterface(__uuidof<U>(), (void**)p->ReleaseAndGetAddressOf());
return ((IUnknown*)ptr_)->QueryInterface(__uuidof<U>(), (void**)p->ReleaseAndGetAddressOf());
}
/// <summary>Converts the current object reference to type <typeparamref name="U"/> and assigns that to a target <see cref="ComPtr{T}"/> value.</summary>
@@ -63,10 +63,10 @@ public unsafe struct ComPtr<T> : IDisposable
/// <returns>The result of <see cref="IUnknown.QueryInterface"/> for the target type <typeparamref name="U"/>.</returns>
/// <remarks>This method will automatically release the target COM object pointed to by <paramref name="other"/>, if any.</remarks>
public readonly HResult As<U>(ref ComPtr<U> other)
where U : unmanaged, IUnknown.Interface
where U : unmanaged
{
U* ptr;
HResult result = ptr_->QueryInterface(__uuidof<U>(), (void**)&ptr);
HResult result = ((IUnknown*)ptr_)->QueryInterface(__uuidof<U>(), (void**)&ptr);
other.Attach(ptr);
return result;
@@ -79,7 +79,7 @@ public unsafe struct ComPtr<T> : IDisposable
/// <remarks>This method will automatically release the target COM object pointed to by <paramref name="other"/>, if any.</remarks>
public readonly HResult AsIID(Guid* riid, ComPtr<IUnknown>* other)
{
return ptr_->QueryInterface(riid, (void**)other->ReleaseAndGetAddressOf());
return ((IUnknown*)ptr_)->QueryInterface(riid, (void**)other->ReleaseAndGetAddressOf());
}
/// <summary>Converts the current object reference to a type indicated by the given IID and assigns that to a target <see cref="ComPtr{T}"/> value.</summary>
@@ -90,7 +90,7 @@ public unsafe struct ComPtr<T> : IDisposable
public readonly HResult AsIID(Guid* riid, ref ComPtr<IUnknown> other)
{
IUnknown* ptr;
HResult result = ptr_->QueryInterface(riid, (void**)&ptr);
HResult result = ((IUnknown*)ptr_)->QueryInterface(riid, (void**)&ptr);
other.Attach(ptr);
return result;
@@ -103,7 +103,7 @@ public unsafe struct ComPtr<T> : IDisposable
{
if (ptr_ != null)
{
var @ref = ptr_->Release();
var @ref = ((IUnknown*)ptr_)->Release();
Debug.Assert((@ref != 0) || (ptr_ != other));
}
ptr_ = other;
@@ -153,28 +153,28 @@ public unsafe struct ComPtr<T> : IDisposable
/// <param name="ptr">The target raw pointer to copy the address of the current COM object to.</param>
/// <returns>The result of <see cref="IUnknown.QueryInterface"/> for the target type <typeparamref name="U"/>.</returns>
public readonly HResult CopyTo<U>(U** ptr)
where U : unmanaged, IUnknown.Interface
where U : unmanaged
{
return ptr_->QueryInterface(__uuidof<U>(), (void**)ptr);
return ((IUnknown*)ptr_)->QueryInterface(__uuidof<U>(), (void**)ptr);
}
/// <summary>Converts the current COM object reference to a given interface type and assigns that to a target <see cref="ComPtr{T}"/>.</summary>
/// <param name="p">The target raw pointer to copy the address of the current COM object to.</param>
/// <returns>The result of <see cref="IUnknown.QueryInterface"/> for the target type <typeparamref name="U"/>.</returns>
public readonly HResult CopyTo<U>(ComPtr<U>* p)
where U : unmanaged, IUnknown.Interface
where U : unmanaged
{
return ptr_->QueryInterface(__uuidof<U>(), (void**)p->ReleaseAndGetAddressOf());
return ((IUnknown*)ptr_)->QueryInterface(__uuidof<U>(), (void**)p->ReleaseAndGetAddressOf());
}
/// <summary>Converts the current COM object reference to a given interface type and assigns that to a target <see cref="ComPtr{T}"/>.</summary>
/// <param name="other">The target reference to copy the address of the current COM object to.</param>
/// <returns>The result of <see cref="IUnknown.QueryInterface"/> for the target type <typeparamref name="U"/>.</returns>
public readonly HResult CopyTo<U>(ref ComPtr<U> other)
where U : unmanaged, IUnknown.Interface
where U : unmanaged
{
U* ptr;
HResult result = ptr_->QueryInterface(__uuidof<U>(), (void**)&ptr);
HResult result = ((IUnknown*)ptr_)->QueryInterface(__uuidof<U>(), (void**)&ptr);
other.Attach(ptr);
return result;
@@ -186,7 +186,7 @@ public unsafe struct ComPtr<T> : IDisposable
/// <returns>The result of <see cref="IUnknown.QueryInterface"/> for the target IID.</returns>
public readonly HResult CopyTo(Guid* riid, void** ptr)
{
return ptr_->QueryInterface(riid, ptr);
return ((IUnknown*)ptr_)->QueryInterface(riid, ptr);
}
/// <summary>Converts the current object reference to a type indicated by the given IID and assigns that to a target <see cref="ComPtr{T}"/> value.</summary>
@@ -195,7 +195,7 @@ public unsafe struct ComPtr<T> : IDisposable
/// <returns>The result of <see cref="IUnknown.QueryInterface"/> for the target IID.</returns>
public readonly HResult CopyTo(Guid* riid, ComPtr<IUnknown>* p)
{
return ptr_->QueryInterface(riid, (void**)p->ReleaseAndGetAddressOf());
return ((IUnknown*)ptr_)->QueryInterface(riid, (void**)p->ReleaseAndGetAddressOf());
}
/// <summary>Converts the current object reference to a type indicated by the given IID and assigns that to a target <see cref="ComPtr{T}"/> value.</summary>
@@ -205,7 +205,7 @@ public unsafe struct ComPtr<T> : IDisposable
public readonly HResult CopyTo(Guid* riid, ref ComPtr<IUnknown> other)
{
IUnknown* ptr;
HResult result = ptr_->QueryInterface(riid, (void**)&ptr);
HResult result = ((IUnknown*)ptr_)->QueryInterface(riid, (void**)&ptr);
other.Attach(ptr);
return result;
@@ -220,7 +220,7 @@ public unsafe struct ComPtr<T> : IDisposable
if (pointer != null)
{
ptr_ = null;
_ = pointer->Release();
_ = ((IUnknown*)pointer)->Release();
}
}
@@ -322,7 +322,7 @@ public unsafe struct ComPtr<T> : IDisposable
if (temp != null)
{
_ = temp->AddRef();
_ = ((IUnknown*)temp)->AddRef();
}
}
@@ -335,7 +335,7 @@ public unsafe struct ComPtr<T> : IDisposable
if (temp != null)
{
ptr_ = null;
@ref = temp->Release();
@ref = ((IUnknown*)temp)->Release();
}
return @ref;

View File

@@ -1093,7 +1093,7 @@ public partial struct ShaderMacro
[Guid("8ba5fb08-5195-40e2-ac58-0d989c3a0102")]
[NativeTypeName("struct ID3DBlob : IUnknown")]
[NativeInheritance("IUnknown")]
public unsafe partial struct ID3DBlob : ID3DBlob.Interface
public unsafe partial struct ID3DBlob
{
public static ref readonly Guid IID_ID3DBlob
{
@@ -1154,11 +1154,7 @@ public unsafe partial struct ID3DBlob : ID3DBlob.Interface
[VtblIndex(3)]
public void* GetBufferPointer()
{
#if NET6_0_OR_GREATER
return ((delegate* unmanaged<ID3DBlob*, void*>)(lpVtbl[3]))((ID3DBlob*)Unsafe.AsPointer(ref this));
#else
return ((delegate* unmanaged[Stdcall]<ID3DBlob*, void*>)(lpVtbl[3]))((ID3DBlob*)Unsafe.AsPointer(ref this));
#endif
}
/// <include file='../Direct3D.xml' path='doc/member[@name="ID3DBlob::GetBufferSize"]/*' />
@@ -1166,16 +1162,9 @@ public unsafe partial struct ID3DBlob : ID3DBlob.Interface
[VtblIndex(4)]
public nuint GetBufferSize()
{
#if NET6_0_OR_GREATER
return ((delegate* unmanaged<ID3DBlob*, nuint>)(lpVtbl[4]))((ID3DBlob*)Unsafe.AsPointer(ref this));
#else
return ((delegate* unmanaged[Stdcall]<ID3DBlob*, nuint>)(lpVtbl[4]))((ID3DBlob*)Unsafe.AsPointer(ref this));
#endif
}
public interface Interface : IUnknown.Interface
{
}
}
/// <include file='../Direct3D.xml' path='doc/member[@name="ID3DDestructionNotifier"]/*' />
@@ -1183,7 +1172,7 @@ public unsafe partial struct ID3DBlob : ID3DBlob.Interface
[Guid("a06eb39a-50da-425b-8c31-4eecd6c270f3")]
[NativeTypeName("struct ID3DDestructionNotifier : IUnknown")]
[NativeInheritance("IUnknown")]
public unsafe partial struct ID3DDestructionNotifier : ID3DDestructionNotifier.Interface
public unsafe partial struct ID3DDestructionNotifier
{
public static ref readonly Guid IID_ID3DDestructionNotifier
{
@@ -1244,11 +1233,7 @@ public unsafe partial struct ID3DDestructionNotifier : ID3DDestructionNotifier.I
[VtblIndex(3)]
public HResult RegisterDestructionCallback(delegate* unmanaged[Stdcall]<void*, void> callbackFn, void* pData, uint* pCallbackID)
{
#if NET6_0_OR_GREATER
return ((delegate* unmanaged<ID3DDestructionNotifier*, delegate* unmanaged[Stdcall]<void*, void>, void*, uint*, int>)(lpVtbl[3]))((ID3DDestructionNotifier*)Unsafe.AsPointer(ref this), callbackFn, pData, pCallbackID);
#else
return ((delegate* unmanaged[Stdcall]<ID3DDestructionNotifier*, delegate* unmanaged[Stdcall]<void*, void>, void*, uint*, int>)(lpVtbl[3]))((ID3DDestructionNotifier*)Unsafe.AsPointer(ref this), callbackFn, pData, pCallbackID);
#endif
}
/// <include file='../Direct3D.xml' path='doc/member[@name="ID3DDestructionNotifier::UnregisterDestructionCallback"]/*' />
@@ -1256,21 +1241,14 @@ public unsafe partial struct ID3DDestructionNotifier : ID3DDestructionNotifier.I
[VtblIndex(4)]
public HResult UnregisterDestructionCallback(uint callbackID)
{
#if NET6_0_OR_GREATER
return ((delegate* unmanaged<ID3DDestructionNotifier*, uint, int>)(lpVtbl[4]))((ID3DDestructionNotifier*)Unsafe.AsPointer(ref this), callbackID);
#else
return ((delegate* unmanaged[Stdcall]<ID3DDestructionNotifier*, uint, int>)(lpVtbl[4]))((ID3DDestructionNotifier*)Unsafe.AsPointer(ref this), callbackID);
#endif
}
public interface Interface : IUnknown.Interface
{
}
}
/// <include file='../Direct3D.xml' path='doc/member[@name="ID3DInclude"]/*' />
/// <unmanaged>ID3DInclude</unmanaged>
public unsafe partial struct ID3DInclude : ID3DInclude.Interface
public unsafe partial struct ID3DInclude
{
public void** lpVtbl;
@@ -1279,11 +1257,7 @@ public unsafe partial struct ID3DInclude : ID3DInclude.Interface
[VtblIndex(0)]
public HResult Open(IncludeType IncludeType, byte** pFileName, void* pParentData, void** ppData, uint* pBytes)
{
#if NET6_0_OR_GREATER
return ((delegate* unmanaged<ID3DInclude*, IncludeType, byte**, void*, void**, uint*, int>)(lpVtbl[0]))((ID3DInclude*)Unsafe.AsPointer(ref this), IncludeType, pFileName, pParentData, ppData, pBytes);
#else
return ((delegate* unmanaged[Stdcall]<ID3DInclude*, IncludeType, byte**, void*, void**, uint*, int>)(lpVtbl[0]))((ID3DInclude*)Unsafe.AsPointer(ref this), IncludeType, pFileName, pParentData, ppData, pBytes);
#endif
}
/// <include file='../Direct3D.xml' path='doc/member[@name="ID3DInclude::Close"]/*' />
@@ -1291,16 +1265,9 @@ public unsafe partial struct ID3DInclude : ID3DInclude.Interface
[VtblIndex(1)]
public HResult Close(void* pData)
{
#if NET6_0_OR_GREATER
return ((delegate* unmanaged<ID3DInclude*, void*, int>)(lpVtbl[1]))((ID3DInclude*)Unsafe.AsPointer(ref this), pData);
#else
return ((delegate* unmanaged[Stdcall]<ID3DInclude*, void*, int>)(lpVtbl[1]))((ID3DInclude*)Unsafe.AsPointer(ref this), pData);
#endif
}
public interface Interface
{
}
}
#endregion Com Types

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -4,9 +4,6 @@
using System.Runtime.CompilerServices;
using Win32.Graphics.Direct3D;
using Win32.Graphics.Dxgi;
using Win32.Graphics.Dxgi.Common;
using static Win32.Graphics.Direct3D11.Apis;
using static Win32.StringUtilities;
namespace Win32.Graphics.Direct3D11;

View File

@@ -7,7 +7,7 @@ using static Win32.Apis;
namespace Win32;
[Guid("00000000-0000-0000-C000-000000000046")]
public unsafe partial struct IUnknown : IUnknown.Interface
public unsafe partial struct IUnknown
{
public static Guid* NativeGuid => (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in IID_IUnknown));
@@ -17,62 +17,20 @@ public unsafe partial struct IUnknown : IUnknown.Interface
[VtblIndex(0)]
public HResult QueryInterface(Guid* riid, void** ppvObject)
{
#if NET6_0_OR_GREATER
return ((delegate* unmanaged<IUnknown*, Guid*, void**, int>)(lpVtbl[0]))((IUnknown*)Unsafe.AsPointer(ref this), riid, ppvObject);
#else
return ((delegate* unmanaged[Stdcall]<IUnknown*, Guid*, void**, int>)(lpVtbl[0]))((IUnknown*)Unsafe.AsPointer(ref this), riid, ppvObject);
#endif
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(1)]
public uint AddRef()
{
#if NET6_0_OR_GREATER
return ((delegate* unmanaged<IUnknown*, uint>)(lpVtbl[1]))((IUnknown*)Unsafe.AsPointer(ref this));
#else
return ((delegate* unmanaged[Stdcall]<IUnknown*, uint>)(lpVtbl[1]))((IUnknown*)Unsafe.AsPointer(ref this));
#endif
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(2)]
public uint Release()
{
#if NET6_0_OR_GREATER
return ((delegate* unmanaged<IUnknown*, uint>)(lpVtbl[2]))((IUnknown*)Unsafe.AsPointer(ref this));
#else
return ((delegate* unmanaged[Stdcall]<IUnknown*, uint>)(lpVtbl[2]))((IUnknown*)Unsafe.AsPointer(ref this));
#endif
}
public interface Interface
{
[VtblIndex(0)]
HResult QueryInterface(Guid* riid, void** ppvObject);
[VtblIndex(1)]
uint AddRef();
[VtblIndex(2)]
uint Release();
}
public partial struct Vtbl<TSelf>
where TSelf : unmanaged, Interface
{
#if NET6_0_OR_GREATER
public delegate* unmanaged<TSelf*, Guid*, void**, int> QueryInterface;
public delegate* unmanaged<TSelf*, uint> AddRef;
public delegate* unmanaged<TSelf*, uint> Release;
#else
public delegate* unmanaged[Stdcall]<TSelf*, Guid*, void**, int> QueryInterface;
public delegate* unmanaged[Stdcall]<TSelf*, uint> AddRef;
public delegate* unmanaged[Stdcall]<TSelf*, uint> Release;
#endif
}
}

View File

@@ -23,17 +23,6 @@ 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>

View File

@@ -14,33 +14,11 @@ namespace Win32;
/// <summary>Provides a set of methods to supplement or replace <see cref="Unsafe" /> and <see cref="MemoryMarshal" />.</summary>
public static unsafe class UnsafeUtilities
{
/// <inheritdoc cref="Unsafe.As{T}(object)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET6_0_OR_GREATER
[return: NotNullIfNotNull("o")]
#endif
public static T? As<T>(this object? o)
where T : class?
{
//Assert(o is null or T);
return Unsafe.As<T>(o);
}
/// <inheritdoc cref="Unsafe.As{TFrom, TTo}(ref TFrom)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref TTo As<TFrom, TTo>(ref TFrom source)
=> ref Unsafe.As<TFrom, TTo>(ref source);
/// <inheritdoc cref="Unsafe.As{TFrom, TTo}(ref TFrom)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Span<TTo> As<TFrom, TTo>(this Span<TFrom> span)
where TFrom : unmanaged
where TTo : unmanaged
{
//Assert(AssertionsEnabled && (SizeOf<TFrom>() == SizeOf<TTo>()));
return CreateSpan(ref As<TFrom, TTo>(ref span.GetReference()), span.Length);
}
/// <inheritdoc cref="Unsafe.As{TFrom, TTo}(ref TFrom)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlySpan<TTo> As<TFrom, TTo>(this ReadOnlySpan<TFrom> span)
@@ -51,29 +29,11 @@ public static unsafe class UnsafeUtilities
return CreateReadOnlySpan(in AsReadOnly<TFrom, TTo>(in span.GetReference()), span.Length);
}
/// <summary>Reinterprets the given native integer as a reference.</summary>
/// <typeparam name="T">The type of the reference.</typeparam>
/// <param name="source">The native integer to reinterpret.</param>
/// <returns>A reference to a value of type <typeparamref name="T" />.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T AsRef<T>(nint source) => ref Unsafe.AsRef<T>((void*)source);
/// <summary>Reinterprets the given native unsigned integer as a reference.</summary>
/// <typeparam name="T">The type of the reference.</typeparam>
/// <param name="source">The native unsigned integer to reinterpret.</param>
/// <returns>A reference to a value of type <typeparamref name="T" />.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T AsRef<T>(nuint source) => ref Unsafe.AsRef<T>((void*)source);
/// <inheritdoc cref="Unsafe.AsRef{T}(in T)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T AsRef<T>(in T source) => ref Unsafe.AsRef(in source);
/// <inheritdoc cref="Unsafe.AsRef{T}(in T)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref TTo AsRef<TFrom, TTo>(in TFrom source)
{
ref var mutable = ref AsRef(in source);
ref var mutable = ref Unsafe.AsRef(in source);
return ref As<TFrom, TTo>(ref mutable);
}
@@ -85,73 +45,21 @@ public static unsafe class UnsafeUtilities
/// <inheritdoc cref="Unsafe.As{TFrom, TTo}(ref TFrom)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref readonly TTo AsReadOnly<TFrom, TTo>(in TFrom source)
=> ref Unsafe.As<TFrom, TTo>(ref AsRef(in source));
/// <inheritdoc cref="Unsafe.AsPointer{T}(ref T)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T* AsReadOnlyPointer<T>(in T source)
where T : unmanaged => AsPointer(ref AsRef(in source));
/// <inheritdoc cref="Unsafe.AsRef{T}(void*)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T AsRef<T>(void* source) => ref Unsafe.AsRef<T>(source);
/// <inheritdoc cref="MemoryMarshal.GetArrayDataReference{T}(T[])" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T GetReference<T>(this T[] array) => ref MemoryMarshal.GetArrayDataReference(array);
/// <inheritdoc cref="MemoryMarshal.GetArrayDataReference{T}(T[])" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T GetReference<T>(this T[] array, int index) => ref Unsafe.Add(ref array.GetReference(), index);
/// <inheritdoc cref="MemoryMarshal.GetArrayDataReference{T}(T[])" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T GetReference<T>(this T[] array, nuint index) => ref Unsafe.Add(ref array.GetReference(), index);
/// <inheritdoc cref="MemoryMarshal.GetReference{T}(Span{T})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T GetReference<T>(this Span<T> span) => ref MemoryMarshal.GetReference(span);
/// <inheritdoc cref="MemoryMarshal.GetReference{T}(Span{T})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T GetReference<T>(this Span<T> span, int index) => ref Unsafe.Add(ref MemoryMarshal.GetReference(span), index);
/// <inheritdoc cref="MemoryMarshal.GetReference{T}(Span{T})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T GetReference<T>(this Span<T> span, nuint index) => ref Unsafe.Add(ref MemoryMarshal.GetReference(span), index);
=> ref Unsafe.As<TFrom, TTo>(ref Unsafe.AsRef(in source));
/// <inheritdoc cref="MemoryMarshal.GetReference{T}(ReadOnlySpan{T})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref readonly T GetReference<T>(this ReadOnlySpan<T> span) => ref MemoryMarshal.GetReference(span);
/// <inheritdoc cref="MemoryMarshal.GetReference{T}(ReadOnlySpan{T})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref readonly T GetReference<T>(this ReadOnlySpan<T> span, int index) => ref Unsafe.Add(ref MemoryMarshal.GetReference(span), index);
/// <inheritdoc cref="MemoryMarshal.GetReference{T}(ReadOnlySpan{T})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref readonly T GetReference<T>(this ReadOnlySpan<T> span, nuint index) => ref Unsafe.Add(ref MemoryMarshal.GetReference(span), index);
/// <summary>Determines if a given reference to a value of type <typeparamref name="T" /> is not a null reference.</summary>
/// <typeparam name="T">The type of the reference</typeparam>
/// <param name="source">The reference to check.</param>
/// <returns><c>true</c> if <paramref name="source" /> is not a null reference; otherwise, <c>false</c>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNotNullRef<T>(in T source) => !IsNullRef(in source);
/// <inheritdoc cref="Unsafe.IsNullRef{T}(ref T)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNullRef<T>(in T source) => Unsafe.IsNullRef(ref AsRef(in source));
/// <inheritdoc cref="Unsafe.NullRef{T}" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T NullRef<T>() => ref Unsafe.NullRef<T>();
public static bool IsNullRef<T>(in T source) => Unsafe.IsNullRef(ref Unsafe.AsRef(in source));
/// <inheritdoc cref="MemoryMarshal.CreateSpan{T}(ref T, int)" />
public static Span<T> CreateSpan<T>(ref T reference, int length) => MemoryMarshal.CreateSpan(ref reference, length);
/// <inheritdoc cref="MemoryMarshal.CreateReadOnlySpan{T}(ref T, int)" />
public static ReadOnlySpan<T> CreateReadOnlySpan<T>(in T reference, int length) => MemoryMarshal.CreateReadOnlySpan(ref AsRef(in reference), length);
public static ReadOnlySpan<T> CreateReadOnlySpan<T>(in T reference, int length) => MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef(in reference), length);
/// <summary>Returns a pointer to the element of the span at index zero.</summary>
/// <typeparam name="T">The type of items in <paramref name="span" />.</typeparam>
@@ -159,7 +67,7 @@ public static unsafe class UnsafeUtilities
/// <returns>A pointer to the item at index zero of <paramref name="span" />.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T* GetPointer<T>(this Span<T> span)
where T : unmanaged => AsPointer(ref span.GetReference());
where T : unmanaged => AsPointer(ref MemoryMarshal.GetReference(span));
/// <summary>Returns a pointer to the element of the span at index zero.</summary>
/// <typeparam name="T">The type of items in <paramref name="span" />.</typeparam>
@@ -167,5 +75,5 @@ public static unsafe class UnsafeUtilities
/// <returns>A pointer to the item at index zero of <paramref name="span" />.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T* GetPointer<T>(this ReadOnlySpan<T> span)
where T : unmanaged => AsPointer(ref AsRef(in span.GetReference()));
where T : unmanaged => AsPointer(ref Unsafe.AsRef(in span.GetReference()));
}

View File

@@ -20,8 +20,4 @@
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Security\" />
</ItemGroup>
</Project>