Reputation: 4900
Imports System.Runtime.CompilerServices
Public Module ColorExtension
<Extension()> _
Public Function ToColor(ByVal argb As UInteger) As Global.System.Windows.Media.Color
Return Global.System.Windows.Media.Color.FromArgb(CByte((argb And -16777216) >> &H18), CByte((argb And &HFF0000) >> &H10), CByte((argb And &HFF00) >> 8), CByte(argb And &HFF))
End Function
End Module
Public Class Test
Private Sub TestExt()
Dim Col As System.Windows.Media.Color
Col = System.Windows.Media.Color.ToColor(100)'<-- Error
Col.ToColor(100)'<-- Error
End Sub
End Class
When I use this code, I got this exception Error 1 'ToColor' is not a member of 'System.Windows.Media.Color'. C:...\ColorExtension.vb
Please any advice how to develop Extension functions like this Color extension one.
Upvotes: 0
Views: 47
Reputation: 125640
UInteger
class, not on Color
. Type you extends is the type of first method parameter.You can use your extension method in two ways:
ColorExtension.ToColor(100)
100.ToColor()
Upvotes: 1