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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:32:06+00:00 2026-06-10T03:32:06+00:00

If I have the class: class NodeA { public string Name{get;set;} public List<NodeA> Children

  • 0

If I have the class:

class NodeA
{
      public string Name{get;set;}
      public List<NodeA> Children {get;set;}
      // etc some other properties
}

and some other class:

class NodeB
{
      public string Name;
      public IEnumerable<NodeB> Children;
      // etc some other fields;
}

If I need to convert a NodeB object to of type NodeA what will be the best approach? Create a wrapper class? If I have to create a wrapper class how could I create it so that all the wpf controls will still be able to successfully bind to the properties?

  • Reason why I need to create such cast:

    There was an old algorithm that was used on a program that return the list of symbols (IMemorySymbol) in a compiled program. We have worked and created a new algorithm and the fields and properties are somewhat different (ISymbolElem). We need to perform a temporary cast in order to display the properties in the view of the wpf application.

  • 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-10T03:32:07+00:00Added an answer on June 10, 2026 at 3:32 am

    A couple approaches…

    Copy Constructor

    have a NodeA and NodeB contain a constructor which takes the opposite:

    class NodeA 
    { 
        public string Name{get;set;} 
        public List<NodeA> Children {get;set;} 
    
        // COPY CTOR
        public NodeA(NodeB copy)
        {
            this.Name = copy.Name;
            this.Children = new List<NodeA>(copy.Children.Select(b => new NodeA(b));
            //copy other props
        }
    } 
    

    Explicit or Implicit Operator

    • http://msdn.microsoft.com/en-us/library/xhbhezf4.aspx
    • http://msdn.microsoft.com/en-us/library/z5z9kes2.aspx

    explicit you would cast like NodeA a = (NodeA)b;, while implicit you can skip the parens.

    public static explicit operator NodeA(NodeB b)
    {
        //if copy ctor is defined you can call one from the other, else
        NodeA a = new NodeA();
        a.Name = b.Name;
        a.Children = new List<NodeA>();
    
        foreach (NodeB child in b.Children)
        {
            a.Children.Add((NodeA)child);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public with sharing class xml4 { public string x{get;set;} public string c{get;set;} List<ArtemisVC__Company_View_Extensions__c> mcs{get;
I have a class: public class Car { public string Model {get;set;} public string
I have a hierarchical data classes like public class MyNode { public string Name
I have a class like the following: class node { public: node* parent; std::list<node*>
I have the following object: public class MyClass { public int Id { get;
I have a string array of some file paths: path/to/folder/file.xxx path/to/other/ path/to/file/file.xx path/file.x path/
I have a class: class node { public: node& parent; } I want to
I have a Java class, Node as follows : class Node { public ArrayList<Node>
I have a recursive model like this: public class Node { public int Id
I have this class: public class Source extends Node { protected DistributionSampler delay ;

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.