我已经阅读了有关它的 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.所以,如果我要说的话,使用你提供的代码片段:
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 调用的第一个参数留空,它将使用该属性来确定您的类的默认成员是什么,在您的情况下它是 Main.
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 - 它有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!