I have a class
public class MenuItem
{
// This class have a lot of fixed properties that I can't change
public string Foo { get; set; }
// Child items used to create a tree structure
public IList<MenuItem> Items { get; set; }
}
And now I want to create a new class that inherits from MenuItem that will hold more data that I need.
public class MenuItemData<T> : MenuItem
{
public T Data { get; set; }
public new IList<MenuItemData<T>> Items { get; set; }
}
But to be able to have the tree structure, I need somehow to "change" the type of Items to be my new MenuItemData<T>, so I used new.
But then, the problem is that when I populate this tree structure with MenuItemData<T>, It only sets the value to the IList<MenuItemData<T>> Items and not the IList<MenuItem> Items which will be used to create the tree structure.
So I need somehow to set both Items for it to work... but I don't know how to do that.
What I tried to do is set the tree structure with the IList<MenuItemData<T>> Items and then traverse the tree and set the hidden property, but I also don't know how I can get the "new" property and set it's value to the hidden property (the "new" property inherits from the hidden property, so I should be able to set the value from one to the other).
Please notice that:
- I cannot change the
MenuItemclass. - If there's a solution without the
new, it will be ok too - If the question is confusing, please let me know and I can give some examples on how I'm traversing the tree.