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

Commit

Permalink
Add support for binding to COM objects in WPF (#36496)
Browse files Browse the repository at this point in the history
* Add support for binding to COM objects in WPF
  • Loading branch information
AaronRobinsonMSFT authored Apr 1, 2019
1 parent 6a0b0ac commit be2a1c4
Showing 1 changed file with 26 additions and 0 deletions.
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)
{
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))]
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");
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

0 comments on commit be2a1c4

Please sign in to comment.