Reputation: 2629
I have the Following structure for my table and datarow:
Public Class MyDataTable(Of MyDataRowDerived)
Public Class MyDataRowBase(Of DataRow)
Public Property MyDescription As String
Public Class MyDataRowDerived(Of MyDataRowBase)
inherits MyDataRowBase
Public overrides Property MyDescription As String
If i create a row from my Table it is of the type MyDataRowDerived
but i don't want to use the overridden properties on it and just the plain ones as in the base class. and tried to achieve it this way:
Dim row As MyDataRowBase = CType(myTable.AddNew(), MyDataRowBase)
Dim retrievedDescription = row.MyDescription
I tough this way i would force the object to believe its just the base class but it is still using the properties from my devired class.
The description returned by my object is as it is implemented in the derived class, but i need the one from the base class
Solutions can be added in C# also, no problem with that ;)
Upvotes: 2
Views: 1826
Reputation: 3289
I don't think you can do what you're looking for. Replacing the functionality of the base class is what overriding is all about. You can access base class members from the derived class, but not from outside classes.
What you could do is add a new property to your derived class that exposes the base class functionality under a different name:
public class MyDataRowBase : DataRow
{
public virtual string MyDescription { get; set; }
}
public class MyDataRowDerived : MyDataRowBase
{
public override string MyDescription { ... }
public string BaseMyDescription
{
get { return base.MyDescription; }
set { base.MyDescription = value; }
}
}
Then you could use BaseMyDescription
if you want to access the value of the base property from an outside class.
It's fairly unusual to want to do something like this, though. If you give some more information about what you're trying to accomplish, it's possible people might have some good suggestions.
Upvotes: 1
Reputation: 62246
Not very clear what you are asking for exactly, but
if you have
public class Base {
public string SomeProperty {get;set;}
}
public class Deived : Base {
public void SomeMethod() {
this.SomeProperty; //It's the same property available in base class
/**If the base property is virtual and you overriden in Derived
write base.SomeProperty **/
}
}
If this is not what you're asking for, please clarify.
Upvotes: 1