I have several objects in C# that's roughly like this:
A: {
Id: 1,
Parent: {
Id: 2,
Parent: {
Id: 3,
Parent: null
}}}
And,
B: {
Id: 4
Parent: {
Id: 2
Parent:
{
Id: 3
Parent: null
}}}
I would like to combine the two and convert so they are inverted:
Combined: {
Id 3:
Child: {
Id 2,
Child: {
Id: 4,
Child: null
Child: { Id: 1,
Child: null
}}}
The classes look like this:
Public Class MyObject {
public string Id;
public MyObject Parent;
}
public Class CombinedObject {
public string Id;
public IList<CombinedObject> Child;
}
This should be very easy and there should be a nice declarative way to do this, right? I can't figure it out without using a lot of ugly loops.