private static void AddElementWhenNameContains(string content, GraphicText text, IGraphicElement parent) { IGraphicElementContainer container = parent as IGraphicElementContainer; if (container != null) { if (container.Name.Contains(content)) { container.Add(text); } foreach (var child in container.GetChildElements()) { AddElementWhenNameContains(content, text, child); } } }
private static void Demo2() { Console.WriteLine("Build a drawing ..."); var drawing = BuildDrawing(); drawing.Draw(); Console.WriteLine("\n----------- Edit the drawing -----------"); Console.WriteLine("adding a text to all elements which contain 'great' "); GraphicText text = new GraphicText("This is a nice graphic", ConsoleColor.DarkBlue); AddElementWhenNameContains("great", text, drawing); Console.WriteLine("\n-----------The drawing after edit ---------"); drawing.Draw(); }