在4.5&QUOT的CallerMemberName属性,能够被伪造和QUOT;? [英] Is the CallerMemberName attribute in 4.5 "able to be faked"?

查看:223
本文介绍了在4.5&QUOT的CallerMemberName属性,能够被伪造和QUOT;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么.NET 4.5引入了 CallerMemberNameAttribute ,这似乎是一个天赐良机,以人与WPF工作和实施 INotifyPropertyChanged的 - 我的问题是这样的:由<击> 4.5 5.0编译器支持固定绑定属性/,或者是更多的是语法糖帮手的环境中,就像人们可以伪造出Visual Studio中通过声明的 ExtensionAttribute 你自己的,神奇地打开LINQ语法?

So .NET 4.5 introduces the CallerMemberNameAttribute, which seems like a godsend to anyone working with WPF and implementing INotifyPropertyChanged - my question is this: Is the attribute intrinsically tied/supported by the 4.5 5.0 compiler, or is it more of a syntactical sugar helper by the environment, much like one could fake out Visual Studio by declaring an ExtensionAttribute of your own, magically turning on LINQ syntax?

编辑:(!对不起乔恩) 我想我询问是否可以使能的 CallerMemberNameAttribute 在.NET 4.0中,通过正确的命名空间的属性重新声明的功能,就像人能使由 ExtensionAttribute 类的适当声明.NET 2.0LINQ查询语法。我强烈的怀疑是没有,自然...

(sorry Jon!) I guess I'm asking if one can "enable" the functionality of the CallerMemberNameAttribute in .NET 4.0 via redeclaration of the attribute in the proper namespace, much like one can "enable" LINQ query syntax in .NET 2.0 by proper declaration of the ExtensionAttribute class. My strong suspicion is no, naturally...

把另一种方式:我想知道我是否可以从 CallerMemberName 的功能中受益,而不必升级到.NET 4.5 / 5

Put yet another way: I want to know if I can benefit from the functionality of CallerMemberName without upgrading to .NET 4.5/5

我希望这是更清晰...

Hopefully that's more clear...

NinjaEdit#2:唉...版本编号惯例是令人困惑的。

NinjaEdit #2: Sigh...version numbering conventions are confusing!

推荐答案

是的,你可以说,就像你可以使用LINQ和.NET 2,如你所说。我使用了.NET 4.0的项目与VS2012编译成功如下:

Yes, you can, exactly as you could use LINQ and .NET 2, as you said. I use the following in a .NET 4.0 project with the VS2012 compiler with success:

namespace System.Runtime.CompilerServices {

    [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
    public sealed class CallerMemberNameAttribute : Attribute {
    }

}

非常的谨慎,大家对项目使用VS2012,否则他们会得到沉默的错误,因为 CallerMemberNameAttribute 并没有做任何事情, 被作为参数传递默认。

Be very careful that everyone on the project is using VS2012, otherwise they'll get silent bugs because CallerMemberNameAttribute didn't do anything and null was passed as the parameter default.

修改2013年6月28日:考虑安装 Microsoft.Bcl 的NuGet包提供 CallerMemberNameAttribute (和一些其他类从.NET 4.5)的.NET 4和Silverlight,而不是做手工。

Edit 2013-06-28: Consider installing the Microsoft.Bcl NuGet package that provides CallerMemberNameAttribute (and some other classes from .NET 4.5) for .NET 4 and Silverlight rather than doing it manually.

这篇关于在4.5&QUOT的CallerMemberName属性,能够被伪造和QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆