如何获得接口成员列表 [英] How to get a list of Interface members

查看:153
本文介绍了如何获得接口成员列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让接口成员列表?我知道System.Reflection.MemberInfo,但它包括了一个对象,而不仅仅是某个接口的一切。



下面是程序,我不知道如何让你因为我没有把它写的界面,但它是标准的Ascom的一部分(的http:// ASCOM-标准.ORG )。

 公共静态无效的Test1()
{
Console.WriteLine (MARK1); //这表明了......
变种类型= typeof运算(Ascom.Interface.ITelescope);
变种构件= type.GetMembers();
Console.WriteLine(members.Count); //给0
的foreach(在成员VAR成员)
{
Console.WriteLine(member.Name); //从这里没有什么
}
Console.WriteLine(mark4); // ...以及本
}


解决方案

如果它是一个COM接口,那么你应该禁用嵌入互操作类型,否则只会插入用于组装成员。我猜你不从装配该接口使用任何方法/属性,这就是为什么他们从来没有被插入,这样你就可以与反思一一列举。 (THX OWO)


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
}

解决方案

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)

这篇关于如何获得接口成员列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆