In a C#, Windows forms app, we have a series of user controls that are associated with menu entry records in a database…
ID Menu Title 1 User Management 4 Group Management 6 System Utilities 12 Configuration Management
A few user controls…
- UserManagement.cs
- GroupManager.cs
- SysUtil.cs
- ConfigurationMan.cs
We’re currently just switching on the ID, but that seems like a very primitive way to accomplish this and has a lot of hard-coded IDs, which I don’t like.
What would be the most appropriate way to read the database entries and load the appropriate user control?
Thanks!
You could store the class names in the database and instance them via reflection. They would need to all implement an interface or all derive from a base class (which I’m assuming you’re doing, extending Control) in order to be dealt with without having to handle each individual class differently.