<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      C# 3.0 語言規(guī)范

       

      C# 3.0 語言規(guī)范  
      從FxCop歸納出來的一些規(guī)范建議     

      一、 Design(設(shè)計(jì))
      1. Abstract types should not have constructors
      抽象類不應(yīng)該聲明構(gòu)造方法
      2. Assemblies should have valid strong names
      程序集應(yīng)該具有強(qiáng)名稱
      3. Avoid empty interfaces
      避免使用空的接口
      4. Avoid excessive parameters on generic types
      避免在泛型類中使用過多的類型參數(shù)
      5. Avoid namespaces with few types
      避免讓名字空間含有過少的類型
      6. Avoid out parameters
      避免使用 out類型的參數(shù)
      7. Collections should implement generic interface
      集合類應(yīng)該實(shí)現(xiàn)泛型接口
      8. Consider passing base types as parameters
      盡量使用基本類型作為參數(shù)
      9. Declare event handlers correctly
      正確的聲明事件處理器,事件處理器不應(yīng)該具有返回值
      10. Declare types in namespaces
      應(yīng)該在名字空間里面定義類型,而不是外面
      11. Default parameters should not be used
      不應(yīng)該使用參數(shù)默認(rèn)值(C#沒有參數(shù)默認(rèn)值)
      12. Define accessors for attribute arguments
      應(yīng)該為特性(特性)的構(gòu)造方法參數(shù)定義訪問器,其名字跟構(gòu)造方法參數(shù)僅首字母大小寫不一樣
      13. Do not catch general exception types
      不要捕捉普通的異常(即System.Exception)
      14. Do not declare protected members in sealed types
      不要在封閉類型中定義受保護(hù)的成員
      15. Do not declare static members on generic types
      不要在泛型類型中使用靜態(tài)成員
      16. Do not declare virtual members in sealed types
      不要在封閉類型中定義虛成員
      17. Do not declare visible instance fields
      不要定義可見的(public/internal)實(shí)例域變量
      18. Do not expose generic lists
      不要直接暴露范型表
      19. Do not hide base class methods
      不要隱藏(使用或者不使用new)基類的方法
      20. Do not nest generic types in member signatures
      不要在成員的簽名(參數(shù)或者返回值)中嵌套泛型類
      21. Do not override operator equals on reference types
      不要在引用類型中重載==操作符
      22. Do not pass types by reference
      不要使用引用(ref or out)傳遞類型
      23. Enum Storage should be Int32
      枚舉應(yīng)該是 Int32 類型的
      24. Enumerators should be strongly typed
      枚舉器應(yīng)該是強(qiáng)類型的
      25. Enums should have zero value
      枚舉應(yīng)該具有0值
      26. Generic methods should provide type parameter
      泛型類的方法應(yīng)該提供類型參數(shù)
      27. ICollection implementations have strongly typed members
      集合接口的實(shí)現(xiàn)中應(yīng)該使用強(qiáng)類型的成員
      28. Implement standard exception constructors
      自定義的異常應(yīng)該實(shí)現(xiàn)異常類的四個(gè)標(biāo)準(zhǔn)構(gòu)造方法
      29. Indexers should not be multidimensional
      索引不應(yīng)該是多維的
      30. Interface methods should be callable by child types
      接口方法應(yīng)該可以被子類調(diào)用
      31. Lists are strongly typed
      表應(yīng)該是強(qiáng)類型的
      32. Mark assemblies with assembly version
      用程序集版本標(biāo)示程序集
      33. Mark assemblies with CLSCompliant
      使用CLSCompliant特性標(biāo)示程序集
      34. Mark assemblies with ComVisible
      使用 System.Runtime.InteropServices.ComVisibleAttribute 特性標(biāo)示程序集
      35. Mark attributes with AttributeUsageAttribute
      使用 AttributeUsageAttribute 特性標(biāo)示特性類
      36. Mark enums with FlagsAttribute
      含有組合的枚舉應(yīng)該使用FlagsAttribute特性標(biāo)示,相反則不應(yīng)該
      37. Members should not expose certain concrete types
      成員(返回值或者參數(shù))不應(yīng)該暴露具體類型,盡量使用接口
      38. Move pinvokes to native methods class
      將調(diào)用移到本地方法類(不是很理解)
      39. Nested types should not be visible
      嵌套類型不應(yīng)該是可見的
      40. Override methods on comparable types
      可比較類型應(yīng)該重寫 equals 等方法
      41. Override operator equals on overriding add and subtract
      在重寫+和-運(yùn)算的時(shí)候應(yīng)該同時(shí)重寫==操作符
      42. Properties should not be write only
      屬性不應(yīng)該是只寫的
      43. Provide ObsoleteAttribute message
      過時(shí)的成員應(yīng)該使用ObsoleteAttribute特性標(biāo)示,并提供相應(yīng)的Message提示使用者
      44. Replace repetitive arguments with params array
      使用參數(shù)數(shù)組代替重復(fù)的參數(shù)
      45. Static holder types should be sealed
      僅含有靜態(tài)成員的類型應(yīng)該聲明為封閉的
      46. Static holder types should not have constructors
      僅含有靜態(tài)成員的類型應(yīng)該具有構(gòu)造方法
      47. String uri overloads call system uri overloads
      使用string類型的uri參數(shù)的重載應(yīng)調(diào)用系統(tǒng)的使用URI類型參數(shù)的重載
      48. Types should not extend certain base types
      類型不應(yīng)該從具體的類(已經(jīng)過派生的類)繼承,比如異常類不應(yīng)該從ApplicationException繼承,而應(yīng)該從System.Exception繼承
      49. Types that own disposable fields should be disposable
      含有可釋放成員的類型應(yīng)該是可以釋放的(實(shí)現(xiàn)IDisposable接口)
      50. Types that own native resources should be disposable
      使用了非托管資源的類型應(yīng)該是可以釋放的(實(shí)現(xiàn)IDisposable接口)
      51. Uri parameters should not be strings
      Uri 參數(shù)不應(yīng)該是string類型的
      52. Uri properties should not be strings
      Uri 屬性不應(yīng)該是string類型的
      53. Uri return values should not be strings
      Uri 類型的返回值不應(yīng)該是string類型的
      54. Use events where appropriate
      在適當(dāng)?shù)臅r(shí)候使用事件
      55. Use generic event handler instances
      使用泛型的事件處理器實(shí)例
      56. Use generics where appropriate
      在適當(dāng)?shù)臅r(shí)候使用范型
      57. Use integral or string argument for indexers
      索引器應(yīng)該使用整數(shù)或者字符串類型的參數(shù)
      58. Use properties where appropriate
      在適當(dāng)?shù)臅r(shí)候使用屬性(而不是以Get或者Set開頭的方法)
      59. Validate arguments of public methods
      對public的方法的參數(shù)應(yīng)該在方法開頭處進(jìn)行檢驗(yàn)(比如是否為null的檢驗(yàn))
      二、 Globalization(全球化)
      1. Avoid duplicate accelerators
      避免在頂層控件中使用重復(fù)的快捷鍵(加速鍵)
      2. Do not hardcode locale specific strings
      不要對本地的特殊字符串(比如特殊的系統(tǒng)路徑)進(jìn)行硬編碼
      3. Do not pass literals as localized parameters
      不要把文本作為需要本地化的參數(shù)直接傳遞(盡量使用資源文件)
      4. Set locale for data types
      為某些數(shù)據(jù)類型設(shè)定區(qū)域和語言屬性(DataSet和DataTable的locale屬性)
      5. Specify CultureInfo
      指定文化信息(地域和語言信息),在調(diào)用接受System.Globalization.CultureInfo 類型參數(shù)的方法時(shí)應(yīng)該傳遞文化信息
      6. Specify IFormatProvider
      指定格式供應(yīng)器,在調(diào)用接受System.IFormatProvider 類型參數(shù)的方法時(shí)應(yīng)該傳遞格式供應(yīng)器
      7. Specify MessageBoxOptions
      指定MessageBox的選項(xiàng),在調(diào)用MessageBox.Show方法時(shí)應(yīng)該傳遞System.Windows.Forms.MessageBoxOptions,特別在某些從右向左閱讀習(xí)慣的區(qū)域

      三、 Interoperability(互操作性)
      1. Auto layout types should not be ComVisible
      自動(dòng)布局的類型不應(yīng)該對Com可見(設(shè)置System.Runtime.InteropServices.ComVisibleAttribute特性為false)
      2. Avoid int64 arguments for VB6 clients
      避免使用int64類型,如果成員可能被Visual Basic 6 COM clients調(diào)用
      3. Avoid non-public fields in ComVisible value types
      避免在一個(gè)標(biāo)記有ComVisible特性的值類型里面包含非公有的實(shí)例域

      4. Avoid overloads in ComVisible interfaces
      避免在一個(gè)標(biāo)記有ComVisible特性的接口內(nèi)聲明重載
      5. Avoid static members in ComVisible types
      避免在一個(gè)標(biāo)記有ComVisible特性的類型
      6. Call GetLastError immediately after pinvoke
      進(jìn)行pinvoke以后應(yīng)該立即使用GetLastError讀取錯(cuò)誤信息
      7. Com registration methods should be matched
      Com注冊方法(標(biāo)記有System.Runtime.InteropServices.ComRegisterFunctionAttribute特性的方法)應(yīng)該是配對的(同時(shí)具有一個(gè)標(biāo)記有System.Runtime.InteropServices.ComUnregisterFunctionAttribute的方法與之匹配)
      8. Com registration methods should not be visible
      Com注冊方法應(yīng)該是不可見的
      9. Com visible type base types should be ComVisible
      標(biāo)記有ComVisible特性的類型的基類同樣應(yīng)從標(biāo)記有ComVisible特性的類繼承
      10. Com visible types should be creatable
      標(biāo)記有ComVisible特性的類型應(yīng)該能夠使用默認(rèn)構(gòu)造器構(gòu)造
      11. Declare PInvokes correctly
      正確定義PInvokes
      12. Do not use AutoDual ClassInterfaceType
      不要把System.Runtime.InteropServices.ClassInterfaceAttribute特性的值設(shè)置為System.Runtime.InteropServices.ClassInterfaceType.AutoDual
      13. Mark boolean pinvoke arguments with MarshalAs
      布爾型的pinvoke參數(shù)應(yīng)該使用System.Runtime.InteropServices.MarshalAsAttribute特性標(biāo)記
      14. Mark ComSource interfaces as IDispatch
      將System.Runtime.InteropServices.ComSourceInterfacesAttribute特性標(biāo)記為System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch.
      15. PInvoke entry points should exist
      Pinvoke應(yīng)該存在入口點(diǎn)
      16. PInvokes should not be visible
      Pinvoke應(yīng)該是可見的
      四、 Naming(命名)
      1. Avoid language specific type names in parameters
      避免在參數(shù)中使用與特定語言相關(guān)的類型(用Uint16代替Ushort)
      2. Avoid type names in parameters
      避免在外部可見的參數(shù)中使用類型名
      3. Compound words should be cased correctly
      復(fù)合詞應(yīng)該使用正確的大小寫(不要將Mutlipart寫成MultiPart,也不要將ToolBar寫成Toolbar,F(xiàn)ileName寫成Filename)
      4. Do not name enum values 'Reserved'
      不要在枚舉值中使用保留字
      5. Do not prefix enum values with type name
      不要在枚舉值使用類型前綴(比如不要使用Digital之類的前綴)
      6. Events should not have before or after prefix
      事件的名稱不應(yīng)該包含before和after前綴(盡量使用ing和ed的后綴)
      7. Flags enums should have plural names
      標(biāo)記有System.FlagsAttribute特性的枚舉應(yīng)該使用復(fù)數(shù)形式的名稱
      8. Identifiers should be cased correctly
      標(biāo)示符(名字空間、類名、屬性名、接口名、方法名等)應(yīng)該使用正確的大小寫(通常以大寫開頭,以后的每個(gè)單詞都首字母大寫)
      9. Identifiers should be spelled correctly
      標(biāo)示符應(yīng)該可以被正確的劃分為不同的單詞
      10. Identifiers should differ by more than case
      標(biāo)示符應(yīng)該不止有大小寫上的不同(因?yàn)槟承┱Z言是不區(qū)分大小寫的)
      11. Identifiers should have correct prefix
      標(biāo)示符應(yīng)該使用正確的前綴(接口應(yīng)該使用字母I開頭)
      12. Identifiers should have correct suffix
      標(biāo)示符應(yīng)該使用正確的后綴
      System.Attribute/Attribute
      System.EventArgs/EventArgs
      System.Exception/Exception
      System.Collections.ICollection/Collection
      System.Collections.IDictionary/Dictionary
      System.Collections.IEnumerable/Collection
      System.Collections.Queue/Collection or Queue
      System.Collections.Stack/Collection or Stack
      System.Collections.Generic.ICollection/Collection
      System.Collections.Generic.IDictionary/Dictionary
      System.Data.DataSet/DataSet
      System.Data.DataTable/Collection or DataTable
      System.IO.Stream/Stream
      System.Security.IPermission/Permission
      System.Security.Policy.IMembershipCondition/Condition
      An event-handlerdelegate./EventHandler
      13. Identifiers should not contain underscores
      標(biāo)示符不應(yīng)該使用下劃線
      14. Identifiers should not have incorrect prefix
      標(biāo)示符不應(yīng)該使用不正確的前綴(比如不應(yīng)使用一個(gè)字母作為前綴)
      15. Identifiers should not have incorrect suffix
      標(biāo)示符不應(yīng)該使用不正確的后綴(不要在不正確的地方使用12中提及的后綴名,和Delegate、Enum、Flags for an enumeration、Impl等后綴名)
      16. Identifiers should not match keywords
      標(biāo)示符不應(yīng)該與系統(tǒng)關(guān)鍵字沖突
      17. Long acronyms should be pascal-cased
      長度大于等于3的縮寫詞應(yīng)該使用pascal的命名規(guī)則,即首字母大寫
      18. Only FlagsAttribute enums should have plural names
      只有標(biāo)記有System.FlagsAttribute特性的枚舉的名稱才應(yīng)該使用復(fù)數(shù),其他時(shí)候應(yīng)該使用單數(shù)
      19. Parameter names should match base declaration
      派生項(xiàng)的參數(shù)名應(yīng)該同基項(xiàng)相吻合(派生類重寫或?qū)崿F(xiàn)的方法應(yīng)該同基項(xiàng)具有相同的參數(shù)名)
      20. Parameter names should not match member names
      方法的參數(shù)名不應(yīng)該同類或接口的成員名一樣
      21. Property names should not match get methods
      屬性名字不應(yīng)該同Get開頭的方法的名稱的后半部分相同
      22. Resource string compound words should be cased correctly
      包含符合單詞的資源字符串應(yīng)該使用正確的大小寫(每個(gè)單詞的首字母大寫)
      23. Resource strings should be spelled correctly
      資源字符串應(yīng)該正確的拼寫
      24. Short acronyms should be uppercase
      短的首字母縮寫詞應(yīng)該全部大寫(比如DB,CR)
      25. Type names should not match namespaces
      類型的名字不應(yīng)該與名字空間的名字相同

      26. Use preferred terms
      優(yōu)先使用某些項(xiàng)目或者名稱,以下這些,后者為優(yōu)先使用的
      ComPlus/EnterpriseServices
      Cancelled/Canceled
      Indices/Indexes
      LogIn/LogOn
      LogOut/LogOff
      SignOn/SignIn
      SignOff/SignOut
      Writeable/Writable
      五、 Performance(性能規(guī)則)
      1. Avoid calls that require unboxing
      避免調(diào)用一個(gè)方法,它返回object類型,而你需要的是一個(gè)值類型(需要對返回值進(jìn)行拆箱操作)
      2. Avoid costly calls where possible
      盡可能的避免進(jìn)行代價(jià)高昂的調(diào)用
      3. Avoid excessive locals
      避免使用過多的局部變量(多于64個(gè),部分可能是編譯器生成的)
      4. Avoid uncalled private code
      避免聲明在程序集內(nèi)從來未被調(diào)用的私有成員(private和internal),以下除外:
      明確的接口成員
      靜態(tài)構(gòu)造方法
      靜態(tài)的Main方法(不含參數(shù)或僅包含一個(gè)string數(shù)組的參數(shù)的)
      序列化構(gòu)造方法
      標(biāo)記有System.Runtime.InteropServices.ComRegisterFunctionAttribute或者 System.Runtime.InteropServices.ComUnregisterFunctionAttribute.特性的
      重寫的方法
      5. Avoid uninstantiated internal classes
      避免聲明不會被實(shí)例化的內(nèi)部類,以下情況除外
      值類型
      抽象類型
      枚舉
      委托
      編譯器生成的數(shù)組類型
      僅含有靜態(tài)成員的內(nèi)部類
      6. Avoid unnecessary string creation
      避免創(chuàng)建不必要的string實(shí)例(猶指‘通過ToLower和ToUpper創(chuàng)建的string’),含以下情況
      對于同一個(gè)string實(shí)例多次調(diào)用ToLower和ToUpper(建議:將返回值賦給一個(gè)局部變量,然后使用此局部變量)
      使用equals,’==‘,!=比較‘通過ToLower和ToUpper創(chuàng)建的string’(建議:使用String.Compare比較)
      向一個(gè)System.Collections.Specialized.HybridDictionary類型的成員傳遞‘通過ToLower和ToUpper創(chuàng)建的string’(建議:HybridDictionary具有一個(gè)指示是否忽略大小寫的參數(shù)的構(gòu)造方法重載,使用此重載并傳遞一個(gè)true值進(jìn)去)
      7. Avoid unsealed attributes
      避免聲明未封閉的特性(attributes)(建議:聲明為sealed/ NotInheritable-vb.net或者abstract)
      8. Avoid unused parameters
      避免在方法聲明中包含不會被使用的參數(shù),以下情況除外
      代理引用的方法
      作為事件處理程序的方法
      抽象方法(abstract)
      虛方法(virtual)
      重寫的方法(override)
      外部方法(extern)
      9. Dispose methods should call SuppressFinalize
      Dispose方法應(yīng)該調(diào)用SuppressFinalize,以請求系統(tǒng)不要調(diào)用其Finalize方法
      10. Do not call properties that clone values in loops
      不要在循環(huán)中使用‘返回一個(gè)Clone的對象的屬性’(每次返回‘引用不同’的對象,會導(dǎo)致創(chuàng)建大量的相同的對象)
      11. Do not cast unnecessarily
      不要進(jìn)行不必要的類型轉(zhuǎn)換(特別是嘗試性的轉(zhuǎn)換,建議:在轉(zhuǎn)換前可以使用is操作符來判斷轉(zhuǎn)換能夠成功)
      12. Do not concatenate strings inside loops
      不要在循環(huán)內(nèi)串聯(lián)string(建議:使用StringBuilder代替string)
      13. Do not ignore method results
      不要忽略方法的返回值(通常調(diào)用string的方法會返回新的string)
      14. Do not initialize unnecessarily
      不要進(jìn)行不必要的初始化(比如將類成員初始化為它的默認(rèn)值)
      15. Initialize reference type static fields inline
      在靜態(tài)成員聲明的時(shí)候直接初始化或者調(diào)用靜態(tài)方法初始化(不要使用靜態(tài)構(gòu)造方法來初始化靜態(tài)成員,靜態(tài)構(gòu)造方法會影響性能),以下情況除外:
      初始化對全局狀態(tài)的影響是代價(jià)高昂的,而且類型在使用前不需要進(jìn)行初始化的
      在不需要訪問該類型的靜態(tài)成員的情況下,全局狀態(tài)的影響就可以被訪問到的
      16. Override equals and operator equals on value types
      對于公有的值類型,重寫equals方法和’==‘操作符(如果你期望用戶對實(shí)例進(jìn)行比較或者排序,或者作為哈希表的鍵)
      17. Prefer jagged arrays over multidimensional
      使用鋸齒形數(shù)組代替多維數(shù)組(當(dāng)數(shù)組各元素的長度可能不一致時(shí))
      注意:公共語言規(guī)范(CLS)不支持鋸齒數(shù)組
      18. Properties should not return arrays
      公有類型的屬性不應(yīng)該返回?cái)?shù)組(數(shù)組類型的屬性無法進(jìn)行寫保護(hù),即使是只讀的,除非每次返回不同的拷貝,但是這樣會讓調(diào)用者產(chǎn)生迷惑。建議:改成方法)
      19. Remove empty finalizers
      移除空的終結(jié)器
      20. Remove unused locals
      移除未使用過的局部變量
      21. Test for empty strings using string length
      使用length屬性測試字符串是否為空(原因:不要使用==””、==String..Empty、Equals(“”)等方法,使用Length屬性的效率是最高的;null==empty比較不會拋出異常;在DotNetFrameWork2里面可以使用IsNullOrEmpty方法來判斷字符串是否為null或者empty)
      22. Use literals where appropriate
      在適當(dāng)?shù)臅r(shí)候使用const代替static readonly(const是編譯時(shí)賦值的)

      posted @ 2008-09-17 22:59  .NET快速開發(fā)框架  閱讀(316)  評論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 欧美成人午夜在线观看视频| 免费人成视频在线观看网站| 四虎国产精品永久在线国在线| 久久91精品牛牛| 成人国产精品三上悠亚久久| 久久精品久久精品久久精品| 亚洲熟女综合色一区二区三区 | 国产成人精品成人a在线观看| 国产色视频一区二区三区| 九九九精品成人免费视频小说| 精品不卡一区二区三区| 中文字幕国产精品第一页| 亚洲护士一区二区三区| 在线天堂最新版资源| 国产suv精品一区二区四| 最新的国产成人精品2020| 国产午夜影视大全免费观看| 亚洲成a人片77777kkkk| 欧美成人精品手机在线| 国产精品亚洲一区二区三区| 亚洲真人无码永久在线| 美女扒开尿口让男人桶| 国产精品午夜无码AV天美传媒| 国产精品三级爽片免费看| 国产精品视频全国免费观看| 人妻精品动漫H无码中字| 精品一区二区久久久久久久网站 | 久久精品国产一区二区三区| 中文字幕日韩国产精品| 国产综合色在线精品| 精品一区二区三区四区色| 国产av国片精品一区二区| 欧美色综合天天久久综合精品| 久久精品一偷一偷国产| caoporn免费视频公开| 亚洲国产成人久久综合三区| 国产精品中文字幕二区| 欧美成人黄在线观看| 久久久亚洲欧洲日产国码aⅴ| 欧美一区二区三区久久综合| 国产精品白浆在线观看免费|