I have the following base, middle and derived classes below::
public class Base
{
[DataMemberAttribute()]
public int ValueBase { get; set; }
[IgnoreForAllAttribute("Param1", "Param2")]
public int IgnoreBase { get; set; }
}
public class Middle : Base
{
[DataMemberAttribute()]
public int ValueMiddle { get; set; }
[IgnoreForAllAttribute("Param1", "Param2")]
public int IgnoreMiddle { get; set; }
}
public class MostDerived : Middle
{
[DataMemberAttribute()]
public int ValueMostDerived { get; set; }
[IgnoreForAllAttribute("Param1", "Param2")]
public int IgnoreMostDerived { get; set; }
}
I need a function that given a type, I need to return DataMemberAttribute attributes for all classes in the hierarchy except for the base.
In addition, all IgnoreForAllAttribute attributes should be ignored for all classes in the graph.
var derivedObject = new MostDerived();
var attributes = MyShinyAttributeFunction(derivedObject.GetType());
// returns [] { ValueMostDerived, ValueMiddle }
Here’s a LINQ sample that assumes DateMemberAttribute and IgnoreForAllAttribute are mutually exclusive
And a sample assuming the attributes are NOT mutually exclusive