C# Some newbie questions about collections
I want to create an Extension. An extension is a component or a module
with default members like a name or a list of views. Component and module
inherit from extension members and implement their specific members.
public class Extension() {
public Name;
public List<View> Views;
// ...
}
public class View {
// ...
}
public class Component : Extension() {
// ...
}
public class Module : Extension() {
// ...
}
I can create a list of extensions like that :
List<Extension> Extensions = new Extensions<Extensions>() {
new Component() { Name = "Component 1" },
new Component() { Name = "Component 2" },
new Module() { Name = "Module" }
}
Now I want to create a menu. A menu can contain a view from my previous
extension :
public class MenuItem {
public string Name;
public View View;
}
List<MenuItem> Menu = new List<MenuItem>() {
new MenuItem(Name = "Menu 1", View = Extensions[0].Views[0]),
new MenuItem(Name = "Menu 2", View = Extensions[2].Views[0])
}
3 questions :
Is this the correct way (I'm newbie on c#) ?,
Is this possible with object initializer to assign an child object without
using index like that : View = Extensions[0].Views[0]
In my code, I can add in a new menu a view from a component or a module.
Is this possible to restrict only for component view ? So in my exemple,
second item is impossible to add.
Thanks
Aliza
No comments:
Post a Comment