Tag Archives: StyleCop Warning

SA1400 : CSharp.Maintainability : The class must have an access modifier.

今天另一個要處理的StyleCop 警告是
SA1400 : CSharp.Maintainability : The class must have an access modifier.

SA1400 : CSharp.Maintainability : The class must have an access modifier.

 

原來在原本的Class Template 是沒有定義 Access Modifier的

SA1400 : CSharp.Maintainability : The class must have an access modifier.

<strong>class Get_Text_CL</strong>
    {
    }

解決方法
只要在Class的開頭加上適當的 Access Modifer 便可以了
E.G. Public, Protected, Private..等等

E.G.

<strong>public class Get_Text_CL</strong>
    {
    }

終於解決了 所有的警告..
StyleCop All Fixed
Happy Coding

SA1642 : CSharp.Documentation : The documentation text within the constructor’s summary tag must begin with the text: Initializes a new instance of the class.

今天繼續嘗試把正在開始開發的Windows Phone 8 App的程式碼符合StyleCop的規定
當我使用StyleCop 檢查我的程式碼時出現了很多警告
E.G.

SA1642 : CSharp.Documentation : The documentation text within the constructor’s summary tag must begin with the text: Initializes a new instance of the class.

以下是我寫在Constructor上寫的Comment

/// <summary>
       /// <strong>This is the constructor of this class</strong>
       /// </summary>
        public MainPage()
        {
            InitializeComponent();

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

誰不知..Style Cop 的規定是要在Constructor 上寫以以下的寫句開頭…
Initializes a new instance of the class.”

/// <summary>
        /// <strong>Initializes a new instance of the <see cref="</strong>MainPage<strong>" /> class</strong>
        /// and predefine variable settings and check ...etc
       /// </summary>
        public MainPage()
        {
            InitializeComponent();

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

Happy Coding

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