I have 2 classes that look exactly the same but reside in different namespaces. One property of the nested class is an array of itself, which allows property nesting/recursion (sort of like a command pattern)
I am trying to convert/cast the class from one namespace to the class in another namespace. I have the below code:
namespace Common.Class
{
public class Root
{
public string Key { get; set; }
public Child[] Children { get; set; }
public class Child
{
public string Content { get; set; }
public Child[] RecursionChild { get; set; }
}
}
}
namespace Uncommon.Class
{
class Root
{
public string Key { get; set; }
public Child[] Children { get; set; }
public class Child
{
public string Content { get; set; }
public Child RecursionChild { get; set; }
}
}
}
The main program
static void Main(string[] args)
{
var commonRoot = new Common.Class.Root
{
Key = "1234-lkij-125l-123o-123s",
Children = new Common.Class.Root.Child[]
{
new Common.Class.Root.Child
{
Content = "Level 1 content",
RecursionChild = new Common.Class.Root.Child[] { }
}
}
};
var uncommonRoot = new Uncommon.Class.Root
{
Key = commonRoot.Key,
Children = commonRoot.Children // here I get error: Cannot implicitly convert type 'Common.Class.Root.Child[]' to 'Uncommon.Class.Root.Child[]'
};
}