Good evening, please help with the composition of the recursive fields of the class. Suppose I have a product of the class InfoObject, in which there is an attribute "Composition" of type Collection (in fact, a table), where the elements are InfoObject and may also have a composition!
The question is how do I create a composition from the class InfoObject, so that I recursively (and with recursion I have a very hard time) ran over the composition of each product.
that is, it will look something like this
InfoObject pvc = product.GetInfoObject("ActualVersion"); var compositionList = pvc.GetCollectionElements("ProductBaselineConfigurationItemList").ToArray(); foreach (var pr in compositionList) { InfoObject pv = pr.GetInfoObject("ActualVersion"); if (pv != null) { //Здесь должна быть рекурсия } } and sample composition template
private abstract class Component { protected readonly string Name; protected Component(string name) { Name = name; } public abstract void Add(Component c); } private class CompositeComponent : Component { private readonly List<Component> _children = new List<Component>(); public CompositeComponent(string name) : base(name) { } public override void Add(Component component) { _children.Add(component); } } class EndComponent : Component { public EndComponent(string name) : base(name) { } public override void Add(Component c) { } } I would also be very grateful if you could help me realize the nesting of such products according to type 1.1, 1.2, 1.1.1, 1.2.1, 1.2.1.2 ...