使用 CompilerServices.Extensions 扩展密封的内在数据类型 - 无法重用?
我定义了以下日期扩展?这
'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
给了我执行此操作的简洁功能:
Public Property MyDateTime() As Date?
rowTest.Item("MyDate") = Me.MyDate.ToObject
但是,当我将编译器定义移动到单独的 DLL 时,即使我引用了现在包含扩展的 Class 项目,ToObject 方法也不再从我的项目中可用。
这是编译器扩展的限制吗?如何获得它们的可重用性?
I defined the following extension of the Date? data type
'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
Which gave me the terse capability to do this:
Public Property MyDateTime() As Date?
rowTest.Item("MyDate") = Me.MyDate.ToObject
But when I moved my compiler definition to a separate DLL, I the ToObject method was no longer available from my project even though I had referenced the Class project which now contained the extension.
Is this a limitation of the Compiler Extensions? HOw do you get reusability out of them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在其他项目的目标文件中包含 .ToObject 命名空间(包含 Nullable 日期扩展的命名空间)。
You'll need to include the .ToObject namespace (the namespace containing your Nullable date extensions) in your target file in the other project.