Extending sealed intrinsic datatypes using CompilerServices.Extensions-No way to reuse?
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.
精彩评论