vendredi 7 février 2020

Reflection - Collect WinForm Controls

DESCRIPTION: I want to take all available controls from over 1000 winforms from many assemblies. I do not want to have a large refactoring effort. (Small tool,the reason is for internal use)

WHAT ALREADY DONE: Got all assemblies, and from every assembly took all types which are intresting for me via type.IsSubclassOf(selectedType).

INFORMATION OF THE MAIN PROJECT: Many of the classes have default constructors some not, others refer to other base classes. The project structure is not so optimal because is a product which developed over 15 years.

PROBLEM: I tried to take all controls via reflection by using Activator.CreateInstance(type) but for many of the classes I took unhandled exceptions or other base class exeptions which were not managable. Another issue I faced during this procceedure was casting. I tried also FormatterServices.GetUninitializedObject(type) but I did not found how or if it is possible to take controls.

QUESTION: Is it possible to collect winForm 'Form' controls with a structure like this without great effort? What could be the different ways to achive this?





Aucun commentaire:

Enregistrer un commentaire