You are confusing some concepts here. The class is declared as NotInheritable
means that no class can inherit from her (abstract
in C#). Inheritance is a basic concept of Object-Oriented Programming and is much broader than an extension.
Partial Classes is a resource of . NET Framework and is nothing more than the separation of the same class into more than one file. In the end you have only one class, with members divided logically. This is very useful in event-based applications such as Windows Form and ASP.NET Webforms, where controls are declared in one file and the logic of handling the user interface in another, but both are the same class.
As to your question it is not possible to "extend" a class this way, but if you want to create a clone it is possible using another namespace
:
Namespace Sistema
Public Class Console
Public Shared Sub WriteLine(ByVal arg As String)
System.Console.WriteLine(arg)
End Sub
End Class
End Namespace
So you can use it like this:
Module Module1
Sub Main()
Sistema.Console.WriteLine("Hello World")
End Sub
End Module
OR
If you really want to override the methods of System
, then you should remove its references from the project. Create a console application and remove all references (in the project properties):
Define the namespace
root as System
:
Hence the code. Keep in mind that this way all the features of the System
were lost, you will have to actually rewrite them:
Public Class Console
Public Shared Sub WriteLine(ByVal arg As String)
' código da sua implementação de escrita no console
End Sub
End Class
Yeah, that’s not what I wanted, I’m trying to create a module to get into the place of class
System.Console
, using Win32native libs. but it’s not working, givingAmbigous
.– CypherPotato
I updated my answer, see if you understand and answer.
– Marcus Vinicius
It worked though, if any app is going to use my Assembly, you’ll have to remove one of the references to use my reference....
– CypherPotato
Exactly, but it’s something that makes perfect sense, since you’re rewriting the namespace.
– Marcus Vinicius
Yes, I am creating an expansion project for the namespace System, and I want to put a method in the class "Console", I can’t use extensions, ta difficult...
– CypherPotato