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

  • Home
  • SEARCH
  • 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 7187767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:55:09+00:00 2026-05-28T18:55:09+00:00

I’ve got an object[] array which contains some mixture of builtin types, like Int/Byte/String,

  • 0

I’ve got an object[] array which contains some mixture of builtin types, like Int/Byte/String, and I’m trying to cast at runtime from object to the correct type, then handing that casted data to a 3rd party library that has Write(builtin type overloads) method.

I thought I could just do Obj.Write((expression yielding System.Type)objArg), but it errors on me.

Here’s a code sample that explains it better:

    object testData = (int)42;
    int final = (GetAType())testData;

    private Type GetAType()
    {
        return typeof(Int32);
    }

Any suggestions?
Alternate ways to accomplish this would be helpful also.

For some context, here’s my original problem.
3rd party library with a bunch of overloads for different types.

3rdPartyLibrary.Write(bool source)
3rdPartyLibrary.Write(int16 source)
3rdPartyLibrary.Write(int32 source)
3rdPartyLibrary.Write(string source)

I’m trying to abstract a layer between 3rdPartyLibrary and the rest of my code

Such that I can have
Object[int32]
Object[int16]
Object[string]
Object[int32]

I’m trying to do something simple seeming, like this (psuedo-coded)

loop Object[]
{
  3rdPartyLibrary.Write( (object[i].GetType()) object[i] )
}

I’ve been reading all the similar sounding question, it looks like this may not be possible?

  • 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-28T18:55:11+00:00Added an answer on May 28, 2026 at 6:55 pm

    What you are looking for would be pointless, as the result still would have to have a single type for all operations, and that would have to be object to handle all the different types.

    Just use a switch for the types that you support:

    foreach (object item in Object) {
      switch (item.GetType().Name) {
        case "System.Int16":
          3rdPartyLibrary.Write((Int16)item);
          break;
        case "System.Int32":
          3rdPartyLibrary.Write((Int32)item);
          break;
        case "System.Boolean":
          3rdPartyLibrary.Write((bool)item);
          break;
        case "System.String":
          3rdPartyLibrary.Write((string)item);
          break;
        default:
          throw new ArgumentException("Unhandled type '" + item.GetType().Name + "'.");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
i got an object with contents of html markup in it, for example: string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.