I could only think of one possible solution. Create your own "wrapper" class handling the type unification/conversion (untested):
class StoredPoint {
PointA pa;
PointB pb;
public StoredPoint (PointA other) {
pa = other;
// pb is null
}
public StoredPoint (PointB other) {
pb = other;
// pa is null
}
public static implicit operator StoredPoint(PointA other) {
return new StoredPoint(other);
}
public static implicit operator StoredPoint(PointB other) {
return new StoredPoint(other);
}
public static implicit operator PointA(StoredPoint point) {
if (pa != null)
return pa;
return PointA(0,0); // some default value in case you can't return null
}
public static implicit operator PointA(StoredPoint point) {
if (pa != null)
return pa;
return PointA(0,0); // some default value in case you can't return null
}
public static implicit operator PointB(StoredPoint point) {
if (pb != null)
return pb;
return PointB(0,0); // some default value in case you can't return null
}
}
Then you could just create a list using List<StoredPoint>
and add both types of points to it. Whether you're able to use the resulting list is some different issue (mostly due to error handling etc.).