DefaultMemberAttribute - 它有什么作用? [英] DefaultMemberAttribute - what does it do?

查看:292
本文介绍了DefaultMemberAttribute - 它有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读到它的MSDN文章。这似乎在内部是C#集的方式,也就是功能是去工作作为索引(是吗?)。现在,我已经看到了下面的例子:

I've already read the MSDN article about it. It seems internally it is the way c# sets which is the function that is going to work as indexer(am I right?). Now, I've seen the following example:

[DefaultMemberAttribute("Main")]
public class Program {

    public static void Main() {
        ...
    }
}

现在,我不明白是什么意思。

Now, I don't get it what it means.

感谢所有。但我仍然无法从索引的东西拿到它的用处,除了。当我们要调用InvokeMember?

Thanks all. But I still can't get its usefulness, apart from the indexer thing. When are we going to call InvokeMember?

推荐答案

我个人从来没有使用过,但据我可以告诉你要定义调用的InvokeMember 。因此,您所提供的,如果我是用code片段说:

I personally have never used it, but as far as I can tell you are defining the default method to be invoked when calling InvokeMember. So, using the code snippet you provided if I was to say:

Program prog = new Program();
typeof(Program).InvokeMember("", null, null, prog, null);

由于我离开的第一个参数空InvokeMember的调用,将使用属性,以确定哪些默认成员是类的,你的情况是主。

Because I left the first argument empty of the InvokeMember call it would use the attribute to determine what the default member is of your class, in your case it is Main.

这篇关于DefaultMemberAttribute - 它有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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