Skip to main content

Posts

Showing posts from June 30, 2019

Generic Method for Class DB table mapping

·       Code for mapping db selection to the class using System; using System.Collections.Generic; using System.Data; using System.Reflection; namespace DataSourceLib {     public class DataSource     {         private DataSource() { }         public DataSource(DataSet data) {             if (data == null ) { data = new DataSet(); }             dataSet = data;         }         private DataSet dataSet { set ; get ; }         public IList<T> GetList< T >()         {             List<T> list = new List<T>();             try             {                 DataTable dt = dataSet.Tables[0];                 foreach (DataRow dr in dt.Rows)                 {                     T obj = (T)Activator.CreateInstance( typeof (T));                     PropertyInfo[] propertyInfos;                     propertyInfos = obj.GetType().GetProperties();                     for ( int i = 0; i < data