Omu*_*Omu 4 .net c# vb.net extension-methods
实际上我不知道他们是否应该工作
我在C#中创建了一个库,人们告诉我,我的一种方法在VB.NET中不能作为扩展名 http://valueinjecter.codeplex.com/Thread/View.aspx?ThreadId=227498
这是方法:
public static PropertyDescriptorCollection GetProps(this object o)
{
return GetProps(o.GetType());
}
Run Code Online (Sandbox Code Playgroud)
通常,C#扩展方法在VB.Net中工作得很好,反之亦然.一个例外是当this参数显式输入时Object.由于遗留原因,VB.Net不支持在键入的引用上使用扩展方法Object.
原因是有可能导致代码以不同的语义静默重新编译.VB.Net(和C#)认为导入包含扩展方法的命名空间不应该导致现有代码的静默重新绑定到扩展方法.如果VB.Net允许扩展方法,Object则后期绑定调用可能会以静默方式重新绑定到扩展方法,从而更改代码.
例如.请考虑在扩展方法之前编写的以下内容.
Dim local As Object = ...
local.GetProps() ' This is a late bound call
Run Code Online (Sandbox Code Playgroud)
如果VB.Net允许GetProps定义扩展方法,Object那么只需导入命名空间就会改变GetProps从后期绑定到扩展方法调用的含义.
| 归档时间: |
|
| 查看次数: |
1426 次 |
| 最近记录: |