Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 268243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:40:21+00:00 2026-05-11T23:40:21+00:00

I think that this problem can be sorted using reflection (a technology which I’m

  • 0

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:

  1. nothing in which case I call
    DoSomeWork(null,null);

  2. an array of KeyValuePairType only,
    in which case I call
    DoSomeWork(KeyValuePairType[],
    null);

  3. an array of KeyValueListPair only,
    in which case I call
    DoSomework(null,
    KeyValueListPair[]);

  4. 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:40:22+00:00Added an answer on May 11, 2026 at 11:40 pm

    Assuming you’ve got LINQ available to you…

    public void Foo(object[] values)
    {
        var pairs = values.OfType<KeyValuePairType>().ToArray();
        var lists = values.OfType<KeyValueListPair>().ToArray();
    
        pairs = pairs.Length == 0 ? null : pairs;
        lists = lists.Length == 0 ? null : lists;
    
        DoSomeWork(pairs, lists);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 188k
  • Answers 188k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It seems by the look of that scrollbar that you… May 12, 2026 at 5:30 pm
  • Editorial Team
    Editorial Team added an answer $ cat m.rb class String def maulin! n slice! n… May 12, 2026 at 5:30 pm
  • Editorial Team
    Editorial Team added an answer You can set Trace.IsEnabled to true in the codebehind. May 12, 2026 at 5:30 pm

Related Questions

I think that this problem can be sorted using reflection (a technology which I'm
A class project involves sorting an array of strings, with each string containing an
I'd like to implement a way to display a list of stored addresses sorted
I was thinking of adding some Achievements to our internal bug-tracking and time logging
I'm trying to import a spreadsheet to our database using SSIS. For some reason

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.