mardi 4 septembre 2018

Activator.CreateInstance alternatives for code optimization

I'm working on generic forms and I use some reflection in the parent forms to handle some tasks. I want do some performance fix if possible, so any help is very appreciated.

below is what I call a BrowseForm

enter image description here

I have the following property on the parent form:

public string CrudName {get;set;}

I set the string name of the Crud form to open at design time, from the property grid of the Browse Form.

finally at runtime when the user clicks on Add New, Edit or Watch buttons I run the below code to open the new form and bind data to it

Type type = Assembly.GetEntryAssembly()
                .DefinedTypes
                .FirstOrDefault(t => t.Name == MyCrudName);


Form MyForm = Activator.CreateInstance(type) as Base4Crud;
//some code here
MyForm.ShowDialog();

so I was wondering if it is possible to achieve the job in a better way. Thanks In advance





Aucun commentaire:

Enregistrer un commentaire