Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get all the controls in a namespace?

How can I get all the controls in a namespace? For example, I want to get the controls in System.Windows.Forms: TextBox, ComboBox etc.

like image 970
deneme Avatar asked Dec 22 '22 14:12

deneme


1 Answers

The notion of a control in a namespace is a bit unclear. You could use reflection to get classes in an assembly in a given namespace which derive from a particular base type. For example:

class Program
{
    static void Main()
    {
        var controlType = typeof(Control);
        var controls = controlType
            .Assembly
            .GetTypes()
            .Where(t => controlType.IsAssignableFrom(t) && 
                        t.Namespace == "System.Windows.Forms"
            );
        foreach (var control in controls)
        {
            Console.WriteLine(control);
        }
    }
}
like image 195
Darin Dimitrov Avatar answered Jan 03 '23 08:01

Darin Dimitrov