public interface IComponent
{
Guid Key { get; set; }
}
public interface ICanHaveChildElement
{
List<IComponent> ChildElement {get;set;}
}
public class BaseComponent : IComponent
{
public Guid Key { get; set; }
}
public class TextBox : BaseComponent, IComponent
{
}
public class Radiobutton : BaseComponent, IComponent
{
}
public class Table : BaseComponent, IComponent, ICanHaveChildElement
{
public List<IComponent> ChildElement { get; set; }
}
public class TestService
{
public void Search(Guid key)
{
List<IComponent> components = new List<IComponent>();
var element = components.FirstOrDefault(p => p.Key == key);
}
}
Hello,
When I search within the components (Textbox, Radio, etc.) that do not have subcomponents in my existing code block as above, I can find the component. However, I cannot find components with subcomponents such as tables. I can find it by checking with if, but since I don't know how many sub-components it will have, it can only be successful in operations with one sub-element.
My question is "key" parameter I want to search the entire list. I want to find even if the element with this key is a sub-element.