DefaultMemberAttribute - what does it do?(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.所以,如果我要说的话,使用你提供的代码片段:
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 - 它有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:DefaultMemberAttribute - 它有什么作用?


基础教程推荐
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01