Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add support for binding to COM objects in WPF #36496

Merged
merged 2 commits into from
Apr 1, 2019
Merged
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 @@ -1555,6 +1555,11 @@ private static TypeDescriptionNode NodeFor(object instance, bool createDelegator
{
Type type = instance.GetType();

if (type.IsCOMObject)
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
{
type = ComObjectType;
}

if (createDelegator)
{
node = new TypeDescriptionNode(new DelegatingTypeDescriptionProvider(type));
Expand Down Expand Up @@ -2889,10 +2894,31 @@ public int Compare(object left, object right)
}
}

[TypeDescriptionProvider(typeof(ComNativeDescriptorProxy))]
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
private sealed class TypeDescriptorComObject
{
}

// This class is being used to aid in diagnosability. The alternative to having this proxy would be
// to set the fully qualified type name in the TypeDescriptionProvider attribute. The issue with the
// string method is the failure is silent during type load making diagnosing the issue difficult.
private sealed class ComNativeDescriptorProxy : TypeDescriptionProvider
{
private readonly TypeDescriptionProvider _comNativeDescriptor;

public ComNativeDescriptorProxy()
{
Assembly assembly = Assembly.Load("System.Windows.Forms");
ericstj marked this conversation as resolved.
Show resolved Hide resolved
Type realComNativeDescriptor = assembly.GetType("System.Windows.Forms.ComponentModel.Com2Interop.ComNativeDescriptor", throwOnError: true);
_comNativeDescriptor = (TypeDescriptionProvider)Activator.CreateInstance(realComNativeDescriptor);
}

public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
{
return _comNativeDescriptor.GetTypeDescriptor(objectType, instance);
}
}

/// <summary>
/// This is a merged type descriptor that can merge the output of
/// a primary and secondary type descriptor. If the primary doesn't
Expand Down