I know this is a simple question for you. But I am a beginner in c#. What I want to achieve is to create a method that will store any type of List of Objects from my Model. e.g List<Person>
.
I have tried to make something like this..
public IEnumerable<T> GetObjects<T>()
{
Type type = typeof(T);
PropertyInfo[] properties = type.GetProperties();
foreach (PropertyInfo item in properties)
{
// store properties
}
List<T> objects = new List<T>();
using (SqlConnection str = GetSqlConnection)
{
// retrieve data from db
//then store it to list of objects
}
return objects;
}
This will enable me to retrieve data using only this method.
Aucun commentaire:
Enregistrer un commentaire