Skip to content

Commit

Permalink
Add new API docs for System.Runtime.InteropServices (#106208)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky authored Aug 9, 2024
1 parent 81d7ff1 commit 2ae5d7a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public void FromUnmanaged(TUnmanagedElement* unmanaged)
/// <summary>
/// Returns the managed value representing the native array.
/// </summary>
/// <returns>A span over managed values of the array.</returns>
public ReadOnlySpan<T> ToManaged()
{
return new ReadOnlySpan<T>(_managedValues!);
Expand All @@ -196,6 +197,7 @@ public ReadOnlySpan<T> ToManaged()
/// <summary>
/// Returns a span that points to the memory where the unmanaged elements of the array are stored.
/// </summary>
/// <param name="numElements">The number of elements in the array.</param>
/// <returns>A span over unmanaged values of the array.</returns>
public ReadOnlySpan<TUnmanagedElement> GetUnmanagedValuesSource(int numElements)
{
Expand All @@ -205,6 +207,7 @@ public ReadOnlySpan<TUnmanagedElement> GetUnmanagedValuesSource(int numElements)
/// <summary>
/// Returns a span that points to the memory where the managed elements of the array should be stored.
/// </summary>
/// <param name="numElements">The number of elements in the array.</param>
/// <returns>A span where managed values of the array should be stored.</returns>
public Span<T> GetManagedValuesDestination(int numElements)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public SwiftSelf(void* value)
/// Represents the Swift 'self' context when the argument is Swift frozen struct T, which is either enregistered into multiple registers,
/// or passed by reference in the 'self' register.
/// </summary>
/// <typeparam name="T">The type of the frozen struct to pass in the 'self' context.</typeparam>
/// <remarks>
/// <para>
/// This struct is used to pass the Swift frozen struct T to Swift functions in the context of interop with .NET.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public static partial class ComVariantMarshaller
// VARIANT_BOOL constants.
private const short VARIANT_TRUE = -1;
private const short VARIANT_FALSE = 0;

/// <summary>
/// Converts a managed object to an unmanaged <see cref="ComVariant"/>.
/// </summary>
/// <param name="managed">The managed object.</param>
/// <returns>A <see cref="ComVariant" /> that represents the provided managed object.</returns>
/// <exception cref="ArgumentException">The type of <paramref name="managed"/> is not supported.</exception>
public static ComVariant ConvertToUnmanaged(object? managed)
{
if (managed is null)
Expand Down Expand Up @@ -103,6 +110,12 @@ private static unsafe bool TryCreateOleVariantForInterfaceWrapper(object managed
}
#pragma warning restore CA1416 // Validate platform compatibility

/// <summary>
/// Converts an unmanaged <see cref="ComVariant"/> to a managed object.
/// </summary>
/// <param name="unmanaged">The unmanaged variant.</param>
/// <returns>A managed object that represents the same value as <paramref name="unmanaged"/>.</returns>
/// <exception cref="ArgumentException">The type of data stored in <paramref name="unmanaged"/> is not supported.</exception>
public static unsafe object? ConvertToManaged(ComVariant unmanaged)
{
#pragma warning disable CS0618 // Type or member is obsolete
Expand Down Expand Up @@ -195,6 +208,10 @@ private static unsafe bool TryCreateOleVariantForInterfaceWrapper(object managed
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <summary>
/// Disposes the unmanaged <see cref="ComVariant"/>.
/// </summary>
/// <param name="unmanaged">The object to dispose.</param>
public static void Free(ComVariant unmanaged) => unmanaged.Dispose();

/// <summary>
Expand Down

0 comments on commit 2ae5d7a

Please sign in to comment.