Windows General Form Template

I am creating a generic Windows Form that accepts T and uses reflection with custom attributes to create labels and input controls at runtime.

Example:

class GenericForm<T>: Form where T : ICloneable<T> { } 

Here is a link to the previous question for the form code: SO question .

This form can take 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 will use reflection to determine data types, validation criteria, preferred control types to use, etc.

Instead of reinventing the wheel, I thought it would be worth asking about this if anyone knows about such frameworks. Needless to say, I'm looking for something simple, not a bulky structure.

+8
generics reflection c # winforms
source share
2 answers

As far as I know, there are no frameworks that generate user interface code at runtime. There are many tools (code generators) that do this before. But you would not have the advantage of โ€œonlyโ€ changing the code โ€” you would have an extra step when you would need to start the code generator.

If you really want to create user interface information at runtime, I would generate attributes for your properties that would tell your user interface generator how to work with this property (if the attribute is not specified) have a default value for your data types). This a lot of coding, but can save you time for small and medium sized projects in the future.

Another thing you can do is externalize your interface information into an XML file and create a generator for this. This is actually the framework that does this - take a look at the re-motion structure. I donโ€™t know if part of the user interface is free, but it has some functions (for example, mixins) that can help you complete your task.

0
source share

eXpressApp Framework (XAF) can generate a user interface on the fly. In the simple case, the programmer will only create business objects and will not care about the user interface at all.

+1
source share

All Articles