Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27353

VS 2012 Extensions within Namespaces

$
0
0
Here is my simplified code:
Code:

Sub TestIt()
    MessageBox.Show(StringMagic.DoMagic("Magic number: ").NewLine.NewLine)
End Sub

Namespace StringMagic
    <HideModuleName()> Public Module Module1
        Public Function DoMagic(s As String) As String
            Return s & New System.Random().Next
        End Function

        <Extension()> Public Function NewLine(s As StringMagic) As String
            Return s & Environment.NewLine
        End Function
    End Module
End Namespace

I don't know how to make extension work in my example. I don't want this extension to work on strings in general (e.g. "Something here".NewLine), just in defined namespace.

Viewing all articles
Browse latest Browse all 27353

Trending Articles