【发布时间】:2010-02-17 00:05:11
【问题描述】:
我找到了几个使扩展方法在 .NET2.0 中工作的方法的链接(The moth、Discord & Rhyme、Stack Overflow)。我也从一位同事那里含糊地听说这会导致图书馆出现一些问题或其他什么?是这样吗?并且所有 3 使用不同的方法:
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class ExtensionAttribute : Attribute {}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class
| AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute {}
}
这些方法有什么区别,你会推荐哪一种?
【问题讨论】:
-
另外,你没有提到“内部”与“公共”...