VB.NET Module - Can I force the use of .Pu

2019-01-29 03:40发布

I have a situation where I have several VB.NET Modules in the same Logical-Module of a large application.

I would like the update function of each module to be public, but I would like users to be forced to qualify the function call with the module name.

ModuleName.Update()

instead of

Update()

Is this possible?

Thanks.

3条回答
混吃等死
2楼-- · 2019-01-29 04:21

Using modules is usually a poor design. Consider replacing them with Classes. A module in VB.NET is simply a static class. In other words it doesn't have to be instanced and you can call module.function. When you replace your modules with classes you will need to instance them. Then you can call class_instance.update with ease.

查看更多
We Are One
3楼-- · 2019-01-29 04:23

No.

The VB.NET specifications automatically use Type Promotion to allow this behavior to occur. The only way to avoid this is to have a type at the namespace that has the same name (Update) which would prevent (defeat) the type promotion provided in VB.NET.

查看更多
Anthone
4楼-- · 2019-01-29 04:28

Yes, it is possible, if you are willing to wrap the module within a namespace of the same name as the module:

    Namespace ModuleName
        Module ModuleName
        ...
        End Module
    End Namespace
查看更多
登录 后发表回答