| 属性 | 值 |
|---|---|
| 规则 ID | IDE0250 |
| 标题 | 可以将结构设为“只读” |
| 类别 | Style |
| Subcategory | 语言规则(修饰符首选项) |
| 适用的语言 | C# |
| 选项 | csharp_style_prefer_readonly_struct |
概述
如果结构的所有成员标记为 readonly,此规则会标记未标记为 readonly 的结构。
选项
选项指定你希望规则强制实施的行为。 若要了解如何配置选项,请参阅选项格式。
csharp_style_prefer_readonly_struct
| 属性 | 值 | 说明 |
|---|---|---|
| 选项名称 | csharp_style_prefer_readonly_struct | |
| 选项值 | true |
当结构的所有字段为 readonly 时,首选将结构设置为 readonly。 |
false |
禁用规则。 | |
| 默认选项值 | true |
示例
// Code with violations.
struct S
{
readonly int i;
}
// Fixed code.
readonly struct S
{
readonly int i;
}
抑制警告
如果只想抑制单个冲突,请将预处理器指令添加到源文件以禁用该规则,然后重新启用该规则。
#pragma warning disable IDE0250
// The code that's violating the rule is on this line.
#pragma warning restore IDE0250
若要对文件、文件夹或项目禁用该规则,请在none中将其严重性设置为 。
[*.{cs,vb}]
dotnet_diagnostic.IDE0250.severity = none
若要禁用所有代码样式规则,请在Style中将类别 none 的严重性设置为 。
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Style.severity = none
有关详细信息,请参阅如何禁止显示代码分析警告。