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# 从 List<List<int>> 中删除重 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
