C#: variable-width storage class for dissimilar objects without inheritance

unhappy_mage

[H]ard|DCer of the Month - October 2005
Joined
Jun 29, 2004
Messages
11,455
I've got what I think will be either a fairly straightforward or impossible question. I'm trying to implement K-D trees as described here in C#. I've got them mostly working (insertion, searching, that kind of thing) by using a data member of type IComparable[] in a non-parametrized class. However, I'd also like to be able to serialize them to XML. So when I try with the current code, I get an exception because IComparables aren't serializable.

So I see two options.
1) Create a new interface that's both IComparable and IXmlSerializable, and use an array of those as my data member.
2) Make KDTree a parameterized class, with a variable number of different arguments. So I want to be able to instantiate a KDTree<int> and a KDTree<string, double, Image> and anything else, as long as it's comparable and serializable.

Sorry I'm not being very clear; this is all a bit hazy for me as well. Any input you can give is appreciated, and any questions you ask for futher clarification will probably be helpful to both of us.
 
Back
Top