I think that this problem can be sorted using reflection (a technology which I'm not too sure about).
My code is receiving some code objects that have been serialised to XML at runtime. When I receive it and deserialise it one field is causing me some hassle.
There is a field that can contain a combination of the following data classes (simplified for clarity):
class KeyValuePairType
{
public string Key;
public string Value;
}
class KeyValueListPair
{
public string Key;
public string[] Value;
}
I receive these into my code as an object[] and I need to determine at runtime what exactly this contains so that I can call an interface on a local object that requires KeyValuePairType[] and KeyValueListPair[] as parameters e.g.
public DoSomeWork(KeyValuePairType[] data1, KeyValueListPair[] data2)
I have the following cases to cope with:
object[] contains:
nothing in which case I call DoSomeWork(null,null);
an array of KeyValuePairType only, in which case I call DoSomeWork(KeyValuePairType[], null);
an array of KeyValueListPair only, in which case I call DoSomework(null, KeyValueListPair[]);
or an array of each, in which case I call DoSomework(KeyValuePairType[], KeyValueListPair[]);
Any ideas are welcome.
Thank you
It turns out that the object array contains a random sequence of discrete objects. Initially I was led to belive that it may be a sequence of discretes and arrays of those objects.
As it is the LINQ statements will cover all eventualities.
Can I say a big thank you to those that that answered. I have posted a +1 for those answering with the LINQ statements.