The solution to this is dot net's reflection. The SimpleReflectionForm takes an object like the Customer below and shows this in a form.
public class Customer
{
public Guid Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public bool Married { get; set; }
}
Just call the form:
Customer c = new Customer
{
Id = Guid.NewGuid(),
Name = "Frank",
Age = 31,
Married = true
};
using (SimpleReflectionForm f
= new SimpleReflectionForm(c, "Id"))
{
f.ShowDialog();
}
The following form is shown:

As you can see the Id is ignored, by the optional parameter string[] propertiesToExclude.
The form supports all native .net types (int, string, datetime, guid etc). Guid and numeric types are verified when the Ok button is pressed.
You can download the source of SimpleReflectionForm here.
Enjoy!
3 comments:
Nice one, was looking and looking for this, thank god I didnt have to write it! Karma
This should be a standard feature of .NET!
i think this also writes back to changes to passed object when Pressed OK button isnt it?? that really good..
Post a Comment