Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 使用CompilerServices.Extensions扩展密封的内部数据类型—无法重用?_.net_Vb.net_Language Features - Fatal编程技术网

.net 使用CompilerServices.Extensions扩展密封的内部数据类型—无法重用?

.net 使用CompilerServices.Extensions扩展密封的内部数据类型—无法重用?,.net,vb.net,language-features,.net,Vb.net,Language Features,我定义了以下日期的延长?数据类型 'Nullable Date Extensions <System.Runtime.CompilerServices.Extension()> _ Public Function ToObject(ByVal thisInstance As Date?) As Object Return If(thisInstance.HasValue, CType(thisInstance, Object), DBNull.Value) End Funct

我定义了以下日期的延长?数据类型

'Nullable Date Extensions
<System.Runtime.CompilerServices.Extension()> _
Public Function ToObject(ByVal thisInstance As Date?) As Object
    Return If(thisInstance.HasValue, CType(thisInstance, Object), DBNull.Value)
End Function
但是,当我将编译器定义移动到一个单独的DLL时,我发现ToObject方法在我的项目中不再可用,即使我引用了现在包含扩展的类项目


这是编译器扩展的限制吗?如何使它们具有可重用性?

您需要在另一个项目的目标文件中包含.ToObject名称空间(包含可为空的日期扩展名的名称空间)

我不知道那是什么名称空间。如果将代码直接复制到eiether项目中,代码就可以工作,这对我来说意味着两个项目中都已经包含了所需的引用。这不仅仅是引用的问题。您需要向目标文件添加一个“imports”语句,导入包含扩展方法的命名空间,“只能在模块内声明扩展方法。通常,定义扩展方法的模块与调用扩展方法的模块不同。相反,包含扩展方法的模块将被导入(如果需要的话)以将其引入范围。在包含Print的模块进入作用域后,可以调用该方法,就好像它是不带参数的普通实例方法一样,例如ToUpper:“
Public Property MyDateTime() As Date?

rowTest.Item("MyDate") = Me.MyDate.ToObject