I’m looking for a way that a Tuple property can receive several tuples like Tuple<int>, Tuple<string>. The next code is an example that I’m trying to do:
public class A
{
public virtual Tuple Condition
{
get;
set;
}
}
public class B: A
{
public override Tuple<int, string> Condition
{
get;
set;
}
}
I’d like to use the Condition property from A class, and use it in other classes like B and asign it an specific Tuple.
B b = new B();
B.Condition = Tuple.Create(2, "Bella");
A a = b;
a.Condition // Here must show B.Condition
Two problems with this approach:
Tuple<T1, T2>andTupleare different classes, and method/property overrides don’t support polymorphism in the return types.Even if they did,
Tuple<T1, T2>does not inherit fromTuple, so it wouldn’t work anyway.You would need to declare the
virtualproperty to be ofobjectand then just cast back and forth when needed. Alternatively, you may want to think about what yourConditionproperty really represents; perhaps a custom class will prove more flexible thanTuples.