c# - How to determine what object[] passed as parameter contains? -
I think this problem should be sorted by reflection (a technique I'm not sure about) Could.
My code is getting some code objects that XML has been serialized at runtime. When I get it and cancel it one area, then I am having some problems.
There is an area in which the following data can be a combination of classes (simple to clarity):
class key value type type {public string key; Public string value; } Class key vulnerabilitypair {public string key; Public string [] value; }
I get it in my code as an object [] and I need to set it on runtime to determine exactly what it is so that I have an interface on a local object CallValueListPair [] data2) P> I have to deal with the following matters:
Adding to the item [] :
-
Nothing, in which case I doSomeWork (empty, zero);
-
The only keyway pair type type, in which case I call DoSomeWork (KeyValuePairType [], Null);
-
An array of KeyValueListPair only, in that case I doSomework (empty, KYvalewerPear []),
-
or each An array, in which case I call DoSomework (KeyValuePairType [], KeyValueListPair []);
Any idea is welcome.
Thank you
It has been found that in the object array there is a random sequence of discrete objects, initially I was given the argument that it The sequence of dissection and arrays can be.
Because it is that the LINQ statement will cover all events.
Am I a big thank you to those who replied. I have posted a +1 for those who answered the LINQ statement.
Believing that you have LINQ available for you ...
public void Foo (object [] value) {var pairs = values.OfType & lt; Kindergart type & gt; (). ToArray (); Var lists = values. Opt. & Lt; Keywalic Piper & gt; (). ToArray (); Couple = couple.lambi == 0? Null: couples; Lists = lists. Long == 0? Empty: list; DoSomeWork (pairs, lists); }
Comments
Post a Comment