using System; using System.Collections.Generic; using System.Data; using System.Text; using System.Reflection; namespace Builder.Construct.Builder { public class ObjectBuilder { #region "--PROPERIES--" private DataSet _dsObjectToBuild; /// <summary> /// Dataset to build from /// </summary> public DataSet pObjectToBuild { get { return _dsObjectToBuild; } set { _dsObjectToBuild = value; } } #endregion #region"--CONSTRUCTOR(S)--" public ObjectBuilder(DataSet dsObjectToBuild) { this._dsObjectToBuild = dsObjectToBuild; } #endregion #region "--METHODS--" public T Build<T>() { T entity = Activator.CreateInstance<T>(); DataRow row = _dsObjectToBuild.Tables[0].Rows[0]; //-- ROLL THROUGH ALL THE PROPERTIES IN THE OBJECT -- foreach (PropertyInfo property in entity.GetType().GetProperties()) if(property.CanWrite && property.CanRead) //check if we can read&write the prop foreach (object ca in property.GetCustomAttributes(false)) //itterate through custom attributes if (ca is DatabaseParameter) //check if we have a DB Parameter property.SetValue(entity, row[property.Name], null); // assign value return entity; } #endregion } }