我想这样做,但出现此错误:
错误1 无法定义新的扩展方法,因为编译器
所需类型“System.Runtime.CompilerServices.ExtensionAttribute”
找不到。您是否缺少对 System.Core.dll 的引用?
[剪掉一些路径的东西]
我在这里看到一些答案说,你必须自己定义这个属性。
我怎么做?
EDIT: 这就是我所拥有的:
[AttributeUsage ( AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method )]
public sealed class ExtensionAttribute : Attribute
{
public static int MeasureDisplayStringWidth ( this Graphics graphics, string text )
{
}
}
Like so:
// you need this once (only), and it must be in this namespace
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class
| AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute {}
}
// you can have as many of these as you like, in any namespaces
public static class MyExtensionMethods {
public static int MeasureDisplayStringWidth (
this Graphics graphics, string text )
{
/* ... */
}
}
或者;只需添加对的引用LINQ桥 http://www.albahari.com/nutshell/linqbridge.aspx.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)