I built a function to create forms for me based on the model I give it.
using MyProject.Models;
...
public partial class CRUDPage : ContentPage
{
public CRUDPage()
{
InitializeComponent();
Teacher teacher = new Teacher
{
id = 1,
name = "John Smith",
DOB = new DateTime(1995, 9, 12),
place = "Hebron",
salary = 20.5
};
//set the content of the page >>> PCL, Xamarin.forms
Content = new FormGenerator<Teacher>().GenerateForm(teacher);
}
}
I'm trying to make the code more dynamic by allowing to create forms using any type of models but with no luck. the code should be something like this.
public partial class CRUDPage : ContentPage
{
public CRUDPage(object entity)
{
InitializeComponent();
Content = new FormGenerator<typeof(entity) >().GenerateForm(entity);
}
}
But the above code doesn't work; looks like Type
is not the same as the Class
itself.
How can I get the "class type" of an object to use it as a generic type in the function?