StyleCop學習筆記 自定義規則

2022-05-18 07:10:55 字數 1673 閱讀 1268

本文將簡單的一步一步的指導這可能有助於學習如何建立自己的規則
1、建立乙個專案。

visual studio建立乙個新的類庫專案.net3.5

2、引用兩個dll,stylecop.dll和stylecop.csharp.dll.

3、新增自定義的規則。

mycustomanalyzer.cs**如下:

using stylecop;

using stylecop.csharp;

namespace mycustomrules

/// /// checks whether specified element conforms custom rule cr0001.

///

private bool checkclasses(

cselement element,

cselement parentelement,

object context)

// continue walking in order to find all classes in file

return true;

} }}

4、新增乙個規則的xml檔案,命名和上面類的名字一樣。

把以下內容寫到mycustomanalyzer.xml檔案中

<?xml version="1.0" encoding="utf-8" ?>

custom rule for demo purposes.

不能用a字母

fires when 'a' letter is used in class name.

5、構建

將這個專案生成dll,把mycustomanalyzer.dll放到stylecop根目錄下。

6、部署

開啟乙個我們要測試的專案**。點選stylecop setting設定用我們的mycoustomrule。

7、點選runstylecop在錯誤警告列表就會顯示檢測出來的規則驗證。如圖:

自定義控制項學習筆記(2 3)

一 三種方法 protected virtual void render htmltextwriter writer 編寫客戶端的呈現 protected virtual void renderchildren htmltextwriter 輸出伺服器控制項的子級內容 protected virtu...

Jquery學習筆記 自定義事件

作用 為了在模組之間解耦合 地球人都知道!基本結構 被觸發端 obj.bind 自定義事件名稱 傳入的資料 處理函式 觸發端 觸發物件.click function event function e,arg1,arg2 document trigger mycustomevent bim baz 乙...

python學習筆記 自定義函式

1 函式的定義 首先,我們要定義乙個函式,以說明這個函式的功能。def square sum a,b c a 2 b 2 return c 這個函式的功能是求兩個數的平方和。首先,def,這個關鍵字通知python 我在定義乙個函式。square sum是函式名。括號中的a,b是函式的引數,是對函式...