![]() |
![]() |
|||
![]() |
||||
![]() |
![]() |
This article explains how to get the actual type behind the System.__ComObject type returned by the .Object property of several classes of the Visual Studio extensibility model. More Information Several classes of the extensibility model provide a property named "Object" of the System.Object type. Among them are the following:
The type is declared as System.Object because depending on the instance, it can return one type or another. For example, the type returned by a toolwindow when calling Window.Object depends on the kind of toolwindow: while the Solution Explorer toolwindow will return an object implementing the EnvDTE.UIHierarchy interface, the Task List toolwindow will return an object implementing the EnvDTE.TaskList interface. However, when you make a call like this to guess its type: MessageBox.Show(objWindow.Object.GetType().FullName) You get "System.__ComObject" as result, which is not very helpful. Instead, to know the actual type behind the COM wrapper, you can use this other statement: MessageBox.Show(Microsoft.VisualBasic.Information.TypeName(objWindow.Object)) The Information module resides in the Microsoft.VisualBasic namespace, inside the Microsoft.VisualBasic.dll assembly, which is added automatically to VB.NET projects but you will need to add it to your project if you are using C#, at least until your add-in is coded. Once you know the actual type, you can cast the object to its actual type and work with it. Follow @VSExtensibility |
Copyright © 2000-2021 MZTools Software. All Rights Reserved. Legal Notice |