gpt4 book ai didi

c# - Visual Studio : GlobalSuppressions. cs:前缀 ~P:用于 SuppressMessage 中的属性目标

转载 作者:行者123 更新时间:2023-12-04 11:14:35 26 4
gpt4 key购买 nike

我在 Visual Studio 2017 中抑制了几条 (IntelliSense) 消息。我在文件 GlobalSuppressions.cs 中创建了条目喜欢:

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Wrong Usage", "DisposableFixer:Undisposed ressource.", Justification = "<Pending>", Scope = "member", Target = "~M:MyProg.Class1.....Method1")]

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "CC0001:You should use 'var' whenever possible.", Justification = "<Pending>", Scope = "member", Target = "~P:MyProg.Class2.Setter1")]

前缀 ~M:~P:在属性 Target 似乎是某种过滤器。他们的意思是什么? The only document I find about Target , is: "It must contain a fully-qualified item name."

最佳答案

我终于找到了documentation I was looking for .它写道:

The first part of the string identifies the kind of member being documented, via a single character followed by a colon. The following kinds of members are defined:




特点
描述



事件


方法(包括构造函数、析构函数和运算符)

N
命名空间


属性(包括索引器)


类型(例如类、委托(delegate)、枚举、接口(interface)和结构)

!
错误字符串;字符串的其余部分提供有关错误的信息。例如,文档生成器为无法解析的链接生成错误信息。


我猜第一个和最后一个条目与抑制消息和领先的 ~ 无关。是约定俗成的。
因此,例如,要抑制整个命名空间中给定类型的所有警告,您可以编写:
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "CC0001:You should use 'var' whenever possible.", Scope = "namespaceanddescendants", Target = "~P:MyProg.Class2.Setter1")]
顺便说一句, Scope 的允许值描述 here :


值(value)
描述


“成员”
禁止对成员发出警告。

“模块”
禁止对程序集发出警告。这是一个适用于整个项目的全局抑制。

“命名空间”
此范围禁止针对命名空间本身发出警告。它不会禁止针对命名空间内的类型发出警告。

“命名空间和后代”
禁止命名空间及其所有后代符号中的警告。遗留代码分析会忽略此值。

“类型”
禁止对类型发出警告。

关于c# - Visual Studio : GlobalSuppressions. cs:前缀 ~P:用于 SuppressMessage 中的属性目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48922211/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com