Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1542,8 +1542,7 @@ private static TypeDescriptionNode NodeFor(object instance, bool createDelegator
{
type = ComObjectType;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
&& ComWrappers.TryGetComInstance(instance, out nint unknown))
else if (TryGetComInstance(instance, out nint unknown))
{
// ComObjectType uses the Windows Forms provided ComNativeDescriptor. It currently has hard Win32
// API dependencies. Even though ComWrappers work with other platforms, restricting to Windows until
Expand Down Expand Up @@ -2538,6 +2537,23 @@ public static void SortDescriptorArray(IList infos)
ArrayList.Adapter(infos).Sort(MemberDescriptorComparer.Instance);
}

/// <summary>
/// Wraps ComWrappers.TryGetComInstance and returns false when not supported
/// </summary>
private static unsafe bool TryGetComInstance(object instance, out IntPtr unknown)
{
unknown = IntPtr.Zero;
try
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
ComWrappers.TryGetComInstance(instance, out unknown);
}
catch (PlatformNotSupportedException)
{
return false;
}
}

/// <summary>
/// This class is a type description provider that works with the IComNativeDescriptorHandler
/// interface.
Expand Down