usingSystem;usingSystem.Collections.Generic;usingSystem.Data.SqlClient;usingSystem.Reflection;namespaceSimpleORM{publicclassORM<T>whereT:new(){privatestringconnectionString;privatestringtableName;publicORM(stringconnectionString,stringtableName){this.connectionString=connectionString;this.tableName=tableName;}publicList<T>SelectAll(){List<T>list=newList<T>();using(SqlConnectionconnection=newSqlConnection(connectionString)){connection.Open();stringsql=$"SELECT * FROM {tableName}";using(SqlCommandcommand=newSqlCommand(sql,connection)){using(SqlDataReaderreader=command.ExecuteReader()){while(reader.Read()){Tobj=newT();PropertyInfo[]properties=typeof(T).GetProperties();foreach(PropertyInfopropertyinproperties){property.SetValue(obj,reader[property.Name]);}list.Add(obj);}}}}returnlist;}publicintInsert(Tobj){using(SqlConnectionconnection=newSqlConnection(connectionString)){connection.Open();stringsql=$"INSERT INTO {tableName} VALUES (";PropertyInfo[]properties=typeof(T).GetProperties();foreach(PropertyInfopropertyinproperties){sql+=$"@{property.Name},";}sql=sql.TrimEnd(',')+")";using(SqlCommandcommand=newSqlCommand(sql,connection)){foreach(PropertyInfopropertyinproperties){command.Parameters.AddWithValue($"@{property.Name}",property.GetValue(obj));}returncommand.ExecuteNonQuery();}}}publicintUpdate(Tobj){using(SqlConnectionconnection=newSqlConnection(connectionString)){connection.Open();stringsql=$"UPDATE {tableName} SET ";PropertyInfo[]properties=typeof(T).GetProperties();foreach(PropertyInfopropertyinproperties){sql+=$"{property.Name}=@{property.Name},";}sql=sql.TrimEnd(',')+" WHERE Id=@Id";using(SqlCommandcommand=newSqlCommand(sql,connection)){foreach(PropertyInfopropertyinproperties){command.Parameters.AddWithValue($"@{property.Name}",property.GetValue(obj));}returncommand.ExecuteNonQuery();}}}publicintDelete(intid){using(SqlConnectionconnection=newSqlConnection(connectionString)){connection.Open();stringsql=$"DELETE FROM {tableName} WHERE Id=@Id";using(SqlCommandcommand=newSqlCommand(sql,connection)){command.Parameters.AddWithValue("@Id",id);returncommand.ExecuteNonQuery();}}}}}