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.
A couple approaches…
Copy Constructor
have a NodeA and NodeB contain a constructor which takes the opposite:
Explicit or Implicit Operator
explicit you would cast like
NodeA a = (NodeA)b;, while implicit you can skip the parens.