資源簡介
本書詳細介紹用C#語言進行程序開發需要掌握的知識和技術。全書由淺入深分三大部分,共21章,部分“基礎知識”,包括.NET基礎知識、C#類型基礎、C#的面向對象技術、字符串、垃圾回收、異常處理;第二部分“C#特性”,包括委托和事件、泛型、反射、數據結構、LINQ的相關技術、動態語言運行時;第三部分“多線程和異步”,包括多線程的概念、多線程同步、異步編程理論與實例、任務并行庫等。本書精選大量案例,循序漸進地講解C#語言,內容豐富而翔實,并給出練習題,幫助讀者更好地鞏固所學知識,提升能力。前言和附錄分別給出.NET程序員開發職位要求、技能等級、進階之路,以及面試寶典,可幫助開發者新人快速進階,找到適合自己的工作。

代碼片段和文件信息
using?System;
using?System.Data.SqlClient;
using?System.Reflection;
using?System.Text;
namespace?MiniORM
{
????public?class?ORMHelper
????{
????????public?string?connStr?{?get;?}
????????public?Type?type?{?get;?}
????????public?ORMHelper(string?s)
????????{
????????????connStr?=?s;
????????}
????????//根據傳入的實體類型建表
????????public?void?CreateTable(Type?type)
????????{
????????????var?sb?=?new?StringBuilder(200);
????????????//獲得表名
????????????var?tableName?=?GetTableName(type);
????????????sb.Append(string.Format(“if?not?exists?(select?*?from?sysobjects?where?name?=?‘{0}‘?and?xtype?=?‘U‘)?“?tableName));
????????????sb.Append(string.Format(“create?table?[{0}]“?tableName));
????????????sb.Append(“(“);
????????????//獲得主鍵名
????????????var?pk?=?GetPK(type);
????????????//使用反射遍歷實體所有的屬性
????????????foreach(var?property?in?type.GetProperties(BindingFlags.Instance?|?BindingFlags.NonPublic?|?BindingFlags.Public))
????????????{
????????????????//獲得特性
????????????????var?attribute?=?property.GetCustomAttributes(typeof(DataFieldAttribute)?false);
????????????????var?column?=?(DataFieldAttribute)attribute[0];
????????????????if?(column.name?==?pk)
????????????????????sb.Append(string.Format(“[{0}]?{1}?IDENTITY?NOT?NULL?PRIMARY?KEY“
????????????????????????column.name
????????????????????????column.type));
????????????????else?
????????????????{
????????????????????sb.Append(string.Format(“[{0}]?{1}?NOT?NULL“
????????????????????????column.name
????????????????????????column.type));
????????????????}
????????????}
????????????var?sql?=?sb.ToString().Substring(0?sb.Length-1)?+?“)“;
????????????//執行方法
????????????ExecuteNonQuery(sql);
????????????Console.WriteLine(“表“?+?tableName?+?“已被建立!“);
????????}
????????//插入一個值
????????public?void?Insert(object?newobject)
????????{
????????????var?type?=?newobject.GetType();
????????????var?tableName?=?GetTableName(type);
????????????var?pk?=?GetPK(type);
????????????object?newobjectPKValue?=?new?object();
????????????//從傳入的對象中反射出pk的值?
????????????foreach(var?property?in?type.GetProperties(BindingFlags.Instance?|?BindingFlags.NonPublic?|?BindingFlags.Public))
????????????{
????????????????if?(property.Name?==?pk)
????????????????{
????????????????????//通過GetValue獲得值
????????????????????newobjectPKValue?=?property.GetValue(newobject);
????????????????????break;
????????????????}
????????????}
????????????//搜索表中是否含有相同PK的記錄
????????????if?(HasExist(type?newobjectPKValue))
????????????{
????????????????Console.WriteLine(“表中已有相同PK的記錄,不能重復插入!“);
????????????????return;
????????????}
????????????var?sb?=?new?StringBuilder(200);
????????????sb.Append(“insert?into?“?+?tableName?+?“?values?(“);
????????????//遍歷傳入的對象的屬性,并獲得它們的值,用以拼湊INSERT語句
????????????foreach?(var?property?in?type.GetProperties())
????????????{
????????????????sb.Append(“‘“);
????????????????sb.Append(property.GetValue(newobject).ToString());
????????????????sb.Append(“‘“);
????????????}
????????????var?sql?=?sb.ToString().Substring(0?sb.Leng
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-09-28?23:07??CodeForCSharpBook-master\
?????文件????????2518??2018-09-28?23:07??CodeForCSharpBook-master\.gitattributes
?????文件????????4305??2018-09-28?23:07??CodeForCSharpBook-master\.gitignore
?????文件????????4992??2018-09-28?23:07??CodeForCSharpBook-master\README.md
?????目錄???????????0??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\
?????目錄???????????0??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\MiniORM\
?????文件????????1095??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\MiniORM\MiniORM.sln
?????目錄???????????0??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\MiniORM\MiniORM\
?????文件?????????184??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\MiniORM\MiniORM\App.config
?????文件????????2347??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\MiniORM\MiniORM\MiniORM.csproj
?????文件????????7312??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\MiniORM\MiniORM\ORMHelper.cs
?????文件????????1055??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\MiniORM\MiniORM\Person.cs
?????文件????????3056??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\MiniORM\MiniORM\Program.cs
?????目錄???????????0??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\MiniORM\MiniORM\Properties\
?????文件????????1286??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\MiniORM\MiniORM\Properties\AssemblyInfo.cs
?????目錄???????????0??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\
?????文件?????????184??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\App.config
?????目錄???????????0??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\LateBinding\
?????文件?????????184??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\LateBinding\App.config
?????文件????????2280??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\LateBinding\LateBinding.csproj
?????文件????????1747??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\LateBinding\Program.cs
?????目錄???????????0??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\LateBinding\Properties\
?????文件????????1294??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\LateBinding\Properties\AssemblyInfo.cs
?????文件????????1467??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\Program.cs
?????目錄???????????0??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\Properties\
?????文件????????1298??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\Properties\AssemblyInfo.cs
?????目錄???????????0??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\ReflectionGeneric\
?????文件?????????184??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\ReflectionGeneric\App.config
?????文件????????1337??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\ReflectionGeneric\Program.cs
?????目錄???????????0??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\ReflectionGeneric\Properties\
?????文件????????1306??2018-09-28?23:07??CodeForCSharpBook-master\第10章?反射\ReflectionLab\ReflectionGeneric\Properties\AssemblyInfo.cs
............此處省略1054個文件信息
- 上一篇:簡易的答題系統
- 下一篇:c#讀取txt文檔中的代碼源程序
評論
共有 條評論