Dynamically Create an instance of class in code
In C#, you can create an instance of class dynamically. For example, you can create an instance of class according to database values, rather than hard coded.
You just need to use reflection.
Code
ObjectHandle obj = Activator.CreateInstance(AssemblyName,className); | |
Controller = (IApp) obj.Unwrap(); |
Please note that, Assembly Name is without ".dll", such as "AdvgenContact.App.WPF", and the class name need to be full qualified, for example, "AdvgenContact.App.WPF.MainApp".
If you wish to know more, please check out our open source project, AdvgenContact.
Trackback address for this post
Trackback URL (right click and copy shortcut/link location)
Feedback awaiting moderation
This post has 112 feedbacks awaiting moderation...
Form is loading...