.netvb.netorganizationpartial-classesconvention

Best alternative approach to define a Partial Module in Vb.Net


SCENARIO


Imagine that you, the programmer, is developing an API with a module file lets say BitmapExtensions.vb which is full of extension methods, each extension method has for example 20 overloads, and this causes the source code to increase miles of lines of code,

then, to be productive in our programming environment sure you would like to sepparate each method into different files (a kind of partial modules with the same module name, like we do with partial classes), however, a partial Module cannot be defined and a Class does not support extension methods in Vb.Net,

this totally breaks the user experiencie and programmer productivity because all are disadvantages, when searching an specific overload or to add more, always requiring the usage of the vertical scrollbar on the Visual Studio code editor to scroll thousands and thousands of lines, or using the search-box to find a method name a lot of times because all the methods with all their overloads are messed in the same file... also, its just very ugly.

QUESTION


Just... if possible, what the hell the programmer could do to organize the source code architecture in these circunstances?.

I really don't want to keep a module file which consists in 3.000 lines of code, I want 500 lines of code in 1 file (which means 1 method with all their overloads) preserving the same name(space), and so on with the other members into sepparated files.

Is this possibly to do in some way?.

PS: Of course translating extension methods to common methods to gain the beneffits of defining partial classes is not an option.


Solution

  • EDIT of August 3rd, 2016

    Partial Modules and Interface are available since VB .Net 14.0.

    Original Answer

    Well, known the fact of Type Promotion with Modules (https://msdn.microsoft.com/en-us/library/xz7s1h1x.aspx), you create one Namespace, then you split it into module files. If all the methods are unique in the namespace, you just have to import the namespace, they will be accessible without having to name the modules...

    I guess that is why modules cannot be partial, because the module name can be omitted if the method is unique.

    File test1.vb

    Namespace Test
       Module Test1
         Function Hello() as String
           ...
         End Function
       End Module
    End Namespace
    

    File test2.vb

    Namespace Test
       Module Test2
         Function Hi() as String
           ...
         End Function
       End Module
    End Namespace
    

    Other File

    Imports Test
    Public Function MyFunc() as String
      Return Test.Hi()
    End Function