mardi 13 octobre 2015

How to get property from multi-layered inheritance

Please bear with me on this... I am a fairly new C# developer, working on a system that is already in place.

I need to get the value of a property to use in some logic, but the problem is, that property is way way up in layers...

This is what I have:

public class AFT
{
    public string Status {get; set;}
}

public class AR : AFT
{
   various properties
}

public class ADAR : AR
{
  various properties
}

public class SCA : ADAR
{
   various properties
}

So there's what, 4 layers of inheritance going on?

Working in a controller for the SCA class, I need to know the value of the "Status" property from the parent AFT class (all the way up at the parent).

I read a bit about using reflection, and bindings, but they all seem to only allow for one layer of inheritance.

The end result is, I need to do something like:

foreach (SCA sca in scaList)
{
    if(sca.ADAR.AR.AFT.status == "Ready")
      {
        do stuff
      }
}

So i need to work with the value of the parent property. I am looking for suggestions on how to do this.

I could try to add a similar "Status" property to the SCA class, and populate it with what I need, and use it directly, but this would involve adding it up/down the entire stack. I was trying to avoid that, but if that's the best solution, then I will go with it.

Otherwise, I was hoping there was a way to work with the highest parent properties.

I do not have the permission to go and re-design everything to make it simpler, and yes I realize I am out of my league. Please be kind when voting, I am doing my best to ask the question in the best way possible. We are very limited in what we can post to ask.

Thanks





Aucun commentaire:

Enregistrer un commentaire