开发者

Extending sealed intrinsic datatypes using CompilerServices.Extensions-No way to reuse?

开发者 https://www.devze.com 2023-01-24 11:16 出处:网络
I defined the following extension of the Date? data type \'Nullable Date Extensions <System.Runtime.CompilerServices.Extension()> _

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 av开发者_运维问答ailable 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?


You'll need to include the .ToObject namespace (the namespace containing your Nullable date extensions) in your target file in the other project.

0

精彩评论

暂无评论...
验证码 换一张
取 消