-1

I am working with a COM library in Visual Basic (VB.NET). I am trying to get a list of properties associated with an Interface; however, I am not able to get a list of interface properties. Can someone direct me on the best way to list properties on an Interface?

Below is some sample code that loops over all the properties of a class called "TextBox". The output from this code is a list all the class properties.

This particular code doesn't seem to work for interfaces. By this I mean that this code doesn't return the properties of an interface.

    Dim txt As New TextBox

    Dim type As Type = txt.GetType()

    Dim properties() As PropertyInfo = type.GetProperties()

    For Each p As PropertyInfo In properties

        OutputWindow(p.Name) 

    Next

Image of COM Library with Interface HYSYS.Valve

jmsrz
  • 1
  • 1
  • Have a look at the Douglas answer in [this](https://stackoverflow.com/questions/358835/getproperties-to-return-all-properties-for-an-interface-inheritance-hierarchy) SO question. – Jeroen Heier May 22 '17 at 15:17

1 Answers1

0

Just replace txt.GetType() with the GetType() operator to specify type names instead:

Dim type As Type = GetType(HYSYS.Valve)

You would only use <object>.GetType() when you already have an existing instance of an object. To get the properties of a type in general, for instance a TextBox, it is better to do GetType(TextBox).

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75
  • I implemented your suggestion; however, the result only returns a single property (i.e. name) but nothing else. If I look at the Interface in the object browser (see image attached to original post) I see a list of properties in addition to name. – jmsrz May 22 '17 at 21:30
  • @jmsrz : That's odd, it worked when I tested it. Can you place a [**breakpoint**](https://blogs.msdn.microsoft.com/visualstudioalm/2016/07/15/7-ways-to-look-at-the-values-of-variables-while-debugging-in-visual-studio/) on the `For Each` line and examine the `properties` array? – Visual Vincent May 23 '17 at 07:23
  • @jmsrz : I haven't heard from you in a few days. How's it going? May I ask if you have the source code to this interface, or if you know where I can find the interface itself? I'd like to try to reproduce the problem. – Visual Vincent May 30 '17 at 20:53
  • Thank you for the followup. The property array lists only a single entry (i.e. name). The code that you recommended technically works but the big question is how do I access the properties that I see in the VB object browser. To answer your question, I have a "Type Library" that add to Visual Studio as a reference. This "Type Library" contains the interface in question. I have a copy of the "Type Library" but I'm not sure how to share it through this forum. @visualvincent – jmsrz Jun 01 '17 at 20:13
  • @jmsrz : Your only option is to upload it to a site like [Dropbox](https://www.dropbox.com/) or [Mediafire](https://www.mediafire.com/) and then send the link to me. – Visual Vincent Jun 01 '17 at 23:00
  • Ok, below is the DropBox link for the "HYSYS Type Library". In this type library you will find an interface for "HYSYS.Valve". Ultimately, I'm trying to access a list of properties for the valve. The image in my original post gives you an idea of what I see in the Visual Studio object browser. [link] (https://www.dropbox.com/s/5egni4vv189m6th/hysysV82.tlb?dl=0) @visualvincent – jmsrz Jun 01 '17 at 23:56
  • @jmsrz : I have now tried everything I can think of and I, like you, only get the `name` property. Sadly this doesn't seem to be possible using reflection... I think this might have something to do with it being a COM library and not a native .NET library. – Visual Vincent Jun 02 '17 at 08:36