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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:52:46+00:00 2026-05-11T06:52:46+00:00

I have a Variable class and and 3 subclasses: VariableBool, VariableLong and VariableDouble. Each

  • 0

I have a Variable class and and 3 subclasses: VariableBool, VariableLong and VariableDouble. Each subclass defines only a value member of the type of the suffix.

Now, I need to transfert objects based on these classes over WCF. I have multiple clients registering their variale to a server. Whenever a value changes on one client, it’s updated in all other clients.

My question is: is there a way to do:

someVar.Value = anotherVar.Value; 

regardless of the type, wihout having to check for type, e.g.:

VariableBool anotherVarBool = anotherVar as VariableBool; if (anotherVarBool != null) {   (someVar as VariableBool).Value = anotherVar.Value; } // check other types... 

What am I missing? Is there a patern of some kind? Could I use reflection? Also, I don’t think I can use Generics because of the WCF (I’ve tried but I could make it work).

Thanks

  • 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. 2026-05-11T06:52:47+00:00Added an answer on May 11, 2026 at 6:52 am

    If you are using mex-generated WCF proxies, then I suspect reflection (or ComponentModel) is indeed the simplest option – something like:

    public static void Copy<T>(T source, T destination,     string propertyName) {     PropertyInfo prop = typeof(T).GetProperty(propertyName);     prop.SetValue(destination, prop.GetValue(source, null), null); } 

    Or if you want to use it even with the variable types as the base-class:

    public static void Copy(object source, object destination,     string propertyName) {     PropertyInfo sourceProp = source.GetType().GetProperty(propertyName);     PropertyInfo destProp = destination.GetType().GetProperty(propertyName);     destProp.SetValue(destination, sourceProp.GetValue(source, null), null); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a member variable that in a class that I want to make
I have a superclass and a set of subclasses. In each subclass, I am
I have a base class and several subclasses. Each sub class has an attribute
I currently have an array of type Class which holds only sub-classes of type
Say I wanted to have one variable in a class always be in some
I have a private class variable that holds a collection of order items: Private
I have a private variable in a class and I am trying to access
I have a variable declared like this in a class: Entity *array[BOARD_SIZE][BOARD_SIZE]; I need
I have a private variable in my class: BOOL isEnabled; and a method: -(void)
I have a variable that I'm using many times in a class and as

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.