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 8188335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:52:32+00:00 2026-06-07T02:52:32+00:00

My function receives a parameter ‘value’, of type object. I want to assign it

  • 0

My function receives a parameter ‘value’, of type object. I want to assign it to a member of an object, but the cast doesn’t happen implicitly, so I need to specify it explicitly. However, I don’t want to actually specify the current type of that member in the object, so I could do this:

positiveOrder.OrderID = (int)value;

But, if business requirements change and OrderIDs are generated and stored in a different way, including a type change to Strings for GUIDS for example, I’ll have to come back here and change it, which is undesirable cohesion. I’ve experimented with various permutations of code like

positiveOrder.OrderID = value as thisOrder.OrderID.GetType();

or

positiveOrder.OrderID = (typeof(thisOrder.OrderID)) value;

But nothing seems to be working. Any ideas on programatically specifying the type to convert to? It can be done at compile time or run time, since the Order class doesn’t change.

  • 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-06-07T02:52:34+00:00Added an answer on June 7, 2026 at 2:52 am

    If positiveOrder.OrderID will always be an integer (even if represented in a string), don’t change the member to be anything but an integer. Instead, expose some method that can deal with different source types.

    For example:

    public void SetOrderID(object value)
    {
        this.OrderID = Convert.ToInt32(value);
    }
    

    See Convert.ToInt32().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JavaScript function that receives a parameter whose value is a fragment
I have a function that receives a query as parameter (as clob type) and
I need to write a function which could create any type object. It receives
HI, I using a compression delphi library that receives a pAnsiChar as parameter. But
Code below contains a JS function that receives as parameter String €€ (Euro sign).
i have a function that receives a function as a parameter. example: function foo(bar:Function):void()
I am not sure how to have a function that receives a class object
I want to set title text of a link calling a function which receives
My function receives a array as parameter: array(6) { [0]=> string(7) usuario [1]=> string(4)
I need to make a template function that receives as parameter a std::container of

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.