Category Archives: StyleCop

SA1633 : CSharp.Documentation : The file has no header, the header Xml is invalid, or the header is not located at the top of the file.

SA1633 : CSharp.Documentation : The file has no header, the header Xml is invalid, or the header is not located at the top of the file.”
SA1633 : CSharp.Documentation : The file has no header, the header Xml is invalid, or the header is not located at the top of the file.

StyleCop 有些守則是要每一個文件上的開首
都要有一段XML碼去簡單說明這個程式碼或文件是用來做什麼..
版權是誰的等等

//-----------------------------------------------------------------------
// <copyright file="Get_Text_CL.cs" company="LookFor.HK">
//     Copyright LookFor.HK. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

SA1633 : CSharp.Documentation : The file has no header, the header Xml is invalid, or the header is not located at the top of the file.

Happy Coding

SA1623 : CSharp.Documentation : The property’s documentation summary text must begin with: Gets or sets

今天遇到的另一個StyleCop 警告是
SA1623 : CSharp.Documentation : The property’s documentation summary text must begin with: Gets or sets
SA1623 : CSharp.Documentation : The property's documentation summary text must begin with: Gets or sets

        /// <summary>
        /// <strong>Date Of Entry</strong>
        /// </summary>
        public string DOE { get; set; }

解決方法
在 [Summary] 是要使用 “Gets or sets” 來開首的.. 即使大小寫不同也會出現上面的警告信息
E.G.

        /// <summary>
        ///<strong> Gets or sets Date Of Entry</strong>
        /// </summary>
        public string DOE { get; set; }

Hope you find it useful

SA1200 : CSharp.Ordering : All using directives must be placed inside of the namespace.

以下的StyleCop警告主要是和Scope 有關的..
SA1200 : CSharp.Ordering : All using directives must be placed inside of the namespace.
SA1200 : CSharp.Ordering : All using directives must be placed inside of the namespace

當你有很多不同的ClassesNamespace
而你的這個Class 和另外一個Namespace上的Class 有相同的名稱上時..
directives放在Namespace內會比較好一點..

這個情況有點複雜..有時候再多加解釋

解決方法:
我們只要把directives放在Namespace內便可以了
E.G. 把程式碼由這個


<strong>using System;</strong>
<strong>using System.Collections.Generic;</strong>
<strong>using System.Linq;</strong>
<strong>using System.Text;</strong>
<strong>using System.Threading.Tasks;</strong>

namespace LGetTextWP8.Classes
{

    class Get_Text_CL
    {
    }
}

SA1200 : CSharp.Ordering : All using directives must be placed inside of the namespace
轉成

namespace LGetTextWP8.Classes
{
  <strong>  using System;</strong>
<strong>    using System.Collections.Generic;</strong>
<strong>    using System.Linq;</strong>
<strong>    using System.Text;</strong>
<strong>    using System.Threading.Tasks;</strong>

    class Get_Text_CL
    {
    }
}

SA1200  CSharp.Ordering  All using directives must be placed inside of the namespace
Happy Coding – Please correct me if my concept is wrong

SA1300 : CSharp.Naming : namespace names begin with an upper-case letter – StyleCop Warning

SA1300 : CSharp.Naming : namespace names begin with an upper-case letter
SA1300 : CSharp.Naming : namespace names begin with an upper-case letter

這個警告是因為我把用來放入自定Helper Class的資料夾用了小寫 來開頭
之後在入面建立的ClassNamespace 便會用了小寫 來定義..

namespace LGetTextWP8.<strong>classes</strong>{

}

解決方法十分簡單
只要把資料夾的開首的一個字母轉成大寫便可以了
SA1300 : CSharp.Naming : namespace names begin with an upper-case letter - Updated Folder

[當然你也是把你的Namespace 也轉成首個字母大寫]

namespace LGetTextWP8.<strong>Classes</strong>{

}

Happy Coding

StyleCop – SA1001: CSharp.Spacing: Invalid spacing around the comma.

今天開始更新我之前寫的ShareChiWaiUtilityLib的程式碼..
希望從現在開始我寫的程式碼會比較有質數一點
使用StyleCop的方法十分簡單 只要在Visual Studio 的Solution Explorer上的Source Code 檔案上按右鍵, 選擇 “Run StyleCop
 photo SA1600ClassMustHaveaDocumentHeader.jpg
之後 結果便會在 Output Windows 的 “Error List” Windows 上的Warning 分頁 上出現

當我執行StyleCop的時候..
第一個收到的Warning是1 “SA1001: CSharp.Spacing: Invalid spacing around the comma.
 photo SA1001InvalidSpacingAroundComma.png

問題是因為我的程式碼上在分號/Comma後沒有留一個空格
tbl.Rows.Add(new Object[] { “00005”,”Beef”,1.99,0.8,”00002″ });
 photo SA1001InvalidSpacingAroundCommaCode.png
解決方法:
只要在分號後加上空格便可以了
tbl.Rows.Add(new Object[] { “00006”, “Broccoli”, 1.09, 0.5, “00003” });

Happy Coding =P