Import VB.NET Classes

I saw some code in which a class is imported instead of an imported class so that all the static members / methods of this class are available. Is this a feature of VB? Or do other languages ​​do this too?

TestClass.vb

public class TestClass public shared function Somefunc() as Boolean return true end function end class 

MainClass.vb

 imports TestClass public class MainClass public sub Main() Somefunc() end sub end class 

These files are located in the App_Code directory. Just curious, because I had never thought about it before, and I had not read about it anywhere.

+4
source share
5 answers

One of the reasons this feature works is the emulation of the Visual Basic 6.0 GlobalMultiUse Option for Instancing. Visual Basic 6.0 does not have the ability to publish modules across a DLL boundary. Instead, you set the instancing property of GlobalMultiUse . It is mainly used for utility classes, such as a class that exports a number of mathematical functions.

Each time you call a class subroutine or function with GlobalMultiUse Instancing , Visual Basic 6.0 creates an instance of the class behind the scenes before the function is called.

It can be abused to generate global functions / variables with all the advantages and disadvantages.

+4
source

Yes, this is a Visual Basic language feature . Although you can create aliases using C # using an instruction , it is not visible that you can import a generic class into scope. Honestly, I only ever used it in a past project that already used it. I see some value, but I'm afraid it might do more harm than good for the future maintainability of your code.

+3
source

I use it when I use the same library a lot of time. A good example is System.Math.

C # does not support this, which I find very annoying.

+2
source

In fact, this function is available because it is a shared function. If you want to remove the general modifier, you still have to create an instance of the class to access it.

To access all the variables and all the functions in the default class, you would like to inherit it.

As far as I know import statement , the class basically connects the direct link to it, without creating a copy.

EDIT for clarity: there are specific VB links in the links, thus explaining the functionality of this related to VB.NET

+1
source

wait, wait, wait ....

I found it this morning that we could output all the objects (class-s) inside any class that need their references using this method / function;

 Protected Overrides Sub Finalize() MyBase.Finalize() End Sub 
-4
source

All Articles