/// <summary> /// Fills the object. /// </summary> /// <param name="dataReader">The data reader.</param> /// <param name="customFillMethod">The custom fill method.</param> /// <param name="fullyPopulate">if set to <c>true</c> [fully populate].</param> /// <returns></returns> public static T FillObject(IDataReader dataReader, CustomFill customFillMethod, bool fullyPopulate) { T returnObject = default(T); // Get properties for type List <PropertyInfo> properties = GetPropertyInfo(); // Get ordinal positions in datareader for each of the properties int[] arrOrdinals = GetOrdinals(properties, dataReader); // read datareader if (dataReader.Read()) { // Fill business object returnObject = CreateObject(dataReader, properties, arrOrdinals); if (customFillMethod != null) { customFillMethod(returnObject, dataReader, fullyPopulate); } } // closeReader datareader if (null != dataReader) { dataReader.Close(); } return(returnObject); }
/// <summary> /// Fills the collection. /// </summary> /// <param name="dataReader">The data reader.</param> /// <param name="customFillMethod">The custom fill method.</param> /// <param name="fullyPopulate">if set to <c>true</c> [fully populate].</param> /// <returns></returns> public static List <T> FillCollection(IDataReader dataReader, CustomFill customFillMethod, bool fullyPopulate) { List <T> items = new List <T>(); if (dataReader != null) { T item; // Get properties for type List <PropertyInfo> properties = GetPropertyInfo(); // Get ordinal positions in datareader int[] arrOrdinals = GetOrdinals(properties, dataReader); // Iterate datareader while (dataReader.Read()) { // Fill business object item = CreateObject(dataReader, properties, arrOrdinals); //call delegate to allow any extra population to occur while the datareader is at the current position if (customFillMethod != null) { customFillMethod(item, dataReader, fullyPopulate); } // Add to collection items.Add(item); } // close datareader if (null != dataReader) { dataReader.Close(); } dataReader.Dispose(); } return(items); }