I am creating a generic Windows Form that accepts T and uses reflection with custom attributes to create labels and input controls at run-time.
Example:
class GenericForm<T>: Form where T : ICloneable<T>
{
}
Here’s a link to a previous question for the form code: SO Question.
This form could accept the following entity class as an example:
class Vehicle: ICloneable<Vehicle>
{
public int Id { get; set; }
public int Name { get; set; }
public int Description { get; set; }
}
As you could imagine, the magic behind the form would use reflection to determine data types, validation criteria, preferred control types to use, etc.
Rather than re-inventing the wheel, I thought it would be worth asking on SO if anyone knows of such frameworks. Needless to say, I’m looking for something simple rather than a bulky framework.
As far as I know, there are no frameworks that generate the UI code at runtime. There are plenty of tools (code-generators) that do this before. But you wouldn’t have the advantage of “only” changing the code – you’d had an extra step where you would need to start the code generator.
If you really want to create the UI information at runtime – I’d generate Attributes for your properties, that would tell your UI generator how to deal with this property (if no Attribute is given – have a default for your datatypes). It’s a lot of coding but could save you time for small to medium projects in the future.
Another thing you could do is to externalize your UI information into an XML file and have a generator for that one. There’s actually a framework that does that – have a look at the re-motion framework. I don’t know if the part of the UI is free but it has some functionality (i.e. mixins) that could help you fulfilling your task.