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 - 它有什么作用?
基础教程推荐
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01