gpt4 book ai didi

c# - .NET 4.0 中的 CallerMemberName 不起作用

转载 作者:IT王子 更新时间:2023-10-29 04:32:48 26 4
gpt4 key购买 nike

我正在尝试通过 BCL 可移植包在 .NET 4.0 中使用 CallerMemberName 属性。它总是返回一个空字符串而不是成员名称。我做错了什么?

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
MessageBox.Show(new class2().CallMe);
}
}

public class class2
{
public string CallMe
{
get
{
return HelpMe();
}
}

private string HelpMe([CallerMemberName] string param = "")
{
return param;
}
}

最佳答案

如果您添加以下内容,定位 4.0 就可以正常工作:

namespace System.Runtime.CompilerServices {
sealed class CallerMemberNameAttribute : Attribute { }
}

关于c# - .NET 4.0 中的 CallerMemberName 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18840924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com