Skip to Content
Professional Visual Basic 2012 and .NET 4.5 Programming
book

Professional Visual Basic 2012 and .NET 4.5 Programming

by Bill Sheldon, Billy Hollis, Rob Windsor, David McCarter, Gastón Hillar, Todd Herman
January 2013
Intermediate to advanced
912 pages
26h 58m
English
Wrox
Content preview from Professional Visual Basic 2012 and .NET 4.5 Programming

Extending the My Namespace

You are not limited to only what the My namespace provides. Just as you can with other namespaces, you can extend this namespace until your heart is content. To show an example of extending the My namespace so that it includes your own functions and properties, in your Console application, create a new module called CompanyExtensions.vb.

The code for the entire module and the associated class is presented here (code file: ProVB_Namespaces\CompanyExtensions.vb):

Namespace My
    <HideModuleName()> _
    Module CompanyOperations
        Private _CompanyExtensions As New CompanyExtensions
        Friend Property CompanyExtensions() As CompanyExtensions
            Get
                Return _CompanyExtensions
            End Get
            Set(ByVal value As CompanyExtensions)
                _CompanyExtensions = value
            End Set
        End Property
    End Module
End Namespace
Public Class CompanyExtensions
    Public ReadOnly Property CompanyDateTime() As DateTime
        Get
            Return DateTime.Now()
        End Get
    End Property
End Class

From this example, you can see that the module CompanyOperations is wrapped inside the My namespace. From there, a single property is exposed—CompanyExtensions. The class, CompanyExtensions, is a reference to the class found directly below in the same file. This class, CompanyExtensions, exposes a single ReadOnly Property called CompanyDateTime.

With this in place, build your application, and you are now ready to see the new expanded My namespace in action. Add the following code snippet to Module1.vb. As you type this you'll find that IntelliSense ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Visual Basic 2012 Programmer's Reference

Visual Basic 2012 Programmer's Reference

Rod Stephens

Publisher Resources

ISBN: 9781118332139Purchase book