I am using DevExpress Components controls.I want to create controls from string Value
like “DevExpress.XtraEditors.TextEdit”.I know I can make this with reflection like
var textBoxType = typeof(Control).Assembly.GetType("System.Windows.Forms.TextBox", true);
var textBox = Activator.CreateInstance(textBoxType);
I want to make this for write little code.but DevExpress have a lot of namespace and class.
Can I create control from string unless give A MainClass? (like my sample code typeof(Control))
if I can not make I have to use alot of if
You need to know which assembly the class is defined in.
For example, all of the editors are in
DevExpress.XtraEditors.vX.Y.dll, ortypeof(BaseEdit).Assembly.If you don’t know which assembly it’s defined in, you can create a collection of DevExpress assemblies (
typeof(GridControl).Assembly, typeof(TreeList).Assembly, ...) and loop through them untilasm.GetType(name)doesn’t returnnull.Note that it will be very slow.