Replicate a class from an assempli and add a new constructor
-
I need to crate a new class which replicate a class in a given assembly but adding also a new constructor and adding new methods. Is it possible?
-
I need to crate a new class which replicate a class in a given assembly but adding also a new constructor and adding new methods. Is it possible?
Yes, it's called inheritance and is a cornerstone of OOP.
Never underestimate the power of human stupidity RAH
-
I need to crate a new class which replicate a class in a given assembly but adding also a new constructor and adding new methods. Is it possible?
If the class is a class (and not a struct) and isn't sealed then you can inherit from it:
public class YourClass : OriginalClass
{
// Recreate the constructors as they aren't inherited
public YourClass(...) : base(...)
{ }// Add whatever you want...
}
If it's a struct or a sealed class then you will need to create a wrapper and replicate all the constructors/properties/methods etc you require:
public WrapperClass
{
private WrappedType value;public WrapperClass(...) { value = new WrappedType(...); } public void DoSomething() { value.DoSomething(); } // Add whatever you want...
}
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
If the class is a class (and not a struct) and isn't sealed then you can inherit from it:
public class YourClass : OriginalClass
{
// Recreate the constructors as they aren't inherited
public YourClass(...) : base(...)
{ }// Add whatever you want...
}
If it's a struct or a sealed class then you will need to create a wrapper and replicate all the constructors/properties/methods etc you require:
public WrapperClass
{
private WrappedType value;public WrapperClass(...) { value = new WrappedType(...); } public void DoSomething() { value.DoSomething(); } // Add whatever you want...
}
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)in may case the base class have not a parameterless constructor, while in the derived I need this one. Is it possible to istantiate the base class in later mathod?
-
in may case the base class have not a parameterless constructor, while in the derived I need this one. Is it possible to istantiate the base class in later mathod?
Not by using inheritance - you would need to use a wrapper as in my second snippet, the base would stay
null
until instanciated.Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
in may case the base class have not a parameterless constructor, while in the derived I need this one. Is it possible to istantiate the base class in later mathod?