分享方式:


這和我喜好設定(IDE0003和IDE0009)

本文說明兩個相關規則和 IDE0003IDE0009

屬性
規則識別碼 IDE0003
職稱 拿掉thisMe 限定性
類別 樣式
子類別 語言規則 ('this.' 和 'Me.' 限定符)
適用語言 C# 和 Visual Basic
選項 dotnet_style_qualification_for_field
dotnet_style_qualification_for_property
dotnet_style_qualification_for_method
dotnet_style_qualification_for_event
屬性
規則識別碼 IDE0009
職稱 新增thisMe 限定性
類別 樣式
子類別 語言規則 ('this.' 和 'Me.' 限定符)
適用語言 C# 和 Visual Basic
選項 dotnet_style_qualification_for_field
dotnet_style_qualification_for_property
dotnet_style_qualification_for_method
dotnet_style_qualification_for_event

概觀

這兩個規則會定義您是否偏好使用 這個 (C#)Me. (Visual Basic) 限定符。 若要強制限定符 不存在 ,請將的 IDE0003 嚴重性設定為警告或錯誤。 若要強制限定符 存在 ,請將的 IDE0009 嚴重性設定為警告或錯誤。

例如,如果您偏好欄位和屬性的限定元,而不是方法或事件,則可以啟用 IDE0009 並設定選項 dotnet_style_qualification_for_field ,並將設定 dotnet_style_qualification_for_propertytrue。 不過,此組態不會標記具有this 和 限定符的方法和Me事件。 若要同時強制執行該方法和事件 沒有 限定符,請啟用 IDE0003

注意

即使您 在建置時啟用程式代碼樣式規則,也不會啟用此規則。 它只會出現在 Visual Studio 編輯器中。

選項。

此規則的相關選項會定義應該套用此樣式喜好設定的下列哪一個符號:

選項值表示true偏好在 C# 和 Me. Visual Basic 中前面加上程式代碼符號this.。 選項值false表示偏好程式代碼專案不要以 或 Me.開頭this.

如需設定選項的詳細資訊,請參閱 選項格式

dotnet_style_qualification_for_field

屬性 數值 Description
選項名稱 dotnet_style_qualification_for_field
選項值 true 偏好在 C# 或 Me. Visual Basic 中以 前面加上this.欄位
false 偏好不要以 或 開頭this.欄位Me.
默認選項值 false
// dotnet_style_qualification_for_field = true
this.capacity = 0;

// dotnet_style_qualification_for_field = false
capacity = 0;
' dotnet_style_qualification_for_field = true
Me.capacity = 0

' dotnet_style_qualification_for_field = false
capacity = 0

dotnet_style_qualification_for_property

屬性 數值 Description
選項名稱 dotnet_style_qualification_for_property
選項值 true 偏好在 C# 或 Me. Visual Basic 中以 前面加上this.屬性。
false 偏好屬性不要以 或 Me.開頭this.
默認選項值 false
// dotnet_style_qualification_for_property = true
this.ID = 0;

// dotnet_style_qualification_for_property = false
ID = 0;
' dotnet_style_qualification_for_property = true
Me.ID = 0

' dotnet_style_qualification_for_property = false
ID = 0

dotnet_style_qualification_for_method

屬性 數值 Description
選項名稱 dotnet_style_qualification_for_method
選項值 true 偏好在 C# 或 Me. Visual Basic 中以 開頭this.的方法。
false 偏好方法不要以 或 Me.開頭this.
默認選項值 false
// dotnet_style_qualification_for_method = true
this.Display();

// dotnet_style_qualification_for_method = false
Display();
' dotnet_style_qualification_for_method = true
Me.Display()

' dotnet_style_qualification_for_method = false
Display()

dotnet_style_qualification_for_event

屬性 數值 Description
選項名稱 dotnet_style_qualification_for_event
選項值 true 偏好在 C# 或 Me. Visual Basic 中使用 開頭this.的事件。
false 偏好事件不要以 或 Me.開頭this.
默認選項值 false
// dotnet_style_qualification_for_event = true
this.Elapsed += Handler;

// dotnet_style_qualification_for_event = false
Elapsed += Handler;
' dotnet_style_qualification_for_event = true
AddHandler Me.Elapsed, AddressOf Handler

' dotnet_style_qualification_for_event = false
AddHandler Elapsed, AddressOf Handler

隱藏警告

如果您想要只隱藏單一違規,請將預處理器指示詞新增至原始程式檔以停用,然後重新啟用規則。

#pragma warning disable IDE0003 // Or IDE0009
// The code that's violating the rule is on this line.
#pragma warning restore IDE0003 // Or IDE0009

若要停用檔案、資料夾或項目的規則,請在組態檔中將其嚴重性設定為 。none

[*.{cs,vb}]
dotnet_diagnostic.IDE0003.severity = none
dotnet_diagnostic.IDE0009.severity = none

若要停用所有程式代碼樣式規則,請將組態檔中類別Style的嚴重性設定為 none

[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Style.severity = none

如需詳細資訊,請參閱 如何隱藏程式代碼分析警告

另請參閱