Like this:
public class remoteStatusCounts : RemoteStatus
{
public int statusCount;
public remoteStatusCounts(RemoteStatus r)
{
Type t = r.GetType();
foreach (PropertyInfo p in t.GetProperties())
{
this.property(p) = p.GetValue(); //example pseudocode
}
}
}
The example is a bit simple (it's from the Jira API - RemoteStatus has 4 properties), but imagine the base class had 30 properties. I don't want to manually set all those values, especially if my inherited class only has a couple of extra properties.
Reflection seems to hint at an answer.
I saw at http://stackoverflow.com/questions/3072249/using-inheritance-in-constructor-publix-x-y that I can call the base class constructor (I think? correct me if I'm wrong), but my base class doesn't have a constructor - it's derived from the jira wsdl
public remoteStatusCounts(RemoteStatus r) : base(r) { //do stuff }
edit
I can imagine 2 valid solutions: the one outlined above, and some sort of keyword like this.baseClass
that is of type(baseclass)
and manipulated as such, acting as a sort of pointer to this
. So, this.baseClass.name = "Johnny"
would be the exact same thing as this.name = "Johnny"
For all intents and purposes, let's assume the baseclass has a copy constructor - that is, this is valid code:
public remoteStatusCounts(RemoteStatus r) {
RemoteStatus mBase = r;
//do work
}
edit2 This question is more of a thought exercise than a practial one - for my purposes, I could've just as easily done this: (assuming my "baseclass" can make copies)
public class remoteStatusCounts
{
public int statusCount;
public RemoteStatus rStatus;
public remoteStatusCounts(RemoteStatus r)
{
rStatus = r;
statusCount = getStatusCount();
}
}