Is there a way to get a list of interface members? I know about System.Reflection.MemberInfo, but it includes everything in an object, not just a certain interface.
Here is the program, I'm not sure how to get you the interface as I didn't write it, but it is part of the Ascom Standard (http://ascom-standards.org).
public static void Test1()
{
Console.WriteLine("mark1"); // this shows up...
var type = typeof(Ascom.Interface.ITelescope);
var members = type.GetMembers();
Console.WriteLine(members.Count); // gives 0
foreach (var member in members)
{
Console.WriteLine(member.Name); //nothing from here
}
Console.WriteLine("mark4"); // ...as well as this
}
You just need to ask for the members for the interface type:
If it is a COM interface, then you should disable "Embed Interop Types", otherwise it will only insert used members in the assembly. I guess you don't use any methods/properties from that interface in the assembly, that's why they never get inserted, so you can list them with reflection. (Thx OWO)
From MSDN:
To get a list of members of some interface, you can just do that: list members of that interface, as others pointed out:
But if you want to know what members of certain type implement that interface, you can use
GetInterfaceMap()
and examine theTargetMethods
field: