CallerMemberName在.NET 4.0中无法正常工作 [英] CallerMemberName in .NET 4.0 not working
本文介绍了CallerMemberName在.NET 4.0中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用CallerMemberName通过BCL便携包属性在.NET 4.0中。它总是返回的成员名称空字符串代替。我究竟做错了什么?
公共部分类Form1中:形态
{
公共Form1中()
{
的InitializeComponent();
的MessageBox.show(新等级2()的CallMe。);
}
}
公共类Class2的
{
公共字符串的CallMe
{
得到
{
返回HelpMe();
}
}
私人字符串HelpMe([CallerMemberName]字符串参数=)
{
返回参数;
}
}
解决方案
我找到了原因,虽然对我来说没有用处。你需要在.NET框架4上安装KB2468871才能够使用。不幸的是我不能要求每个开发人员记得要安装它时,他们设置的开发环境。
I am trying to use CallerMemberName attribute in .NET 4.0 via BCL portability pack. It is always returning empty string instead of member name. What am I doing wrong?
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;
}
}
解决方案
I found the reason though not useful for me. You need to install KB2468871 on top of .net 4 framework to be able to use. Unfortunately I can't ask each developer to remember to install it when they setup development environment.
这篇关于CallerMemberName在.NET 4.0中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文