meziantou/Meziantou.Analyzer
GitHub: meziantou/Meziantou.Analyzer
基于 Roslyn 的 C# 静态分析器,在编码时实时检测 bug、安全风险和性能问题并提供自动修复。
Stars: 1124 | Forks: 64
# Meziantou.Analyzer
[](https://www.nuget.org/packages/Meziantou.Analyzer/)
[](https://www.nuget.org/packages/Meziantou.Analyzer/)
**Meziantou.Analyzer** 是一个强大的 C# Roslyn 分析器,它使用静态分析来检测 bug、暴露安全问题并强制执行最佳实践。它通过在您编写代码时进行分析并在可能的情况下提供自动修复,帮助您尽早发现实际问题——在它们进入生产环境之前。它专为人类开发者和 AI 辅助工作流而设计,可作为保持代码可靠、一致和可维护的安全网。
## 安装
安装 NuGet 包 [Meziantou.Analyzer](https://www.nuget.org/packages/Meziantou.Analyzer/)
```
dotnet package add Meziantou.Analyzer
```
## 规则
如果您已经在使用其他分析器,可以检查[哪些规则与知名分析器重复](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/comparison-with-other-analyzers.md)
|Id|类别|描述|严重程度|是否启用|代码修复|
|--|--------|-----------|:------:|:--------:|:------:|
|[MA0001](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0001.md)|用法|缺少 StringComparison|ℹ️|✔️|✔️|
|[MA0002](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0002.md)|用法|缺少 IEqualityComparer\ 或 IComparer\|⚠️|✔️|✔️|
|[MA0003](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0003.md)|样式|添加参数名以提高可读性|ℹ️|✔️|✔️|
|[MA0004](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0004.md)|用法|使用 Task.ConfigureAwait|⚠️|✔️|✔️|
|[MA0005](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0005.md)|性能|使用 Array.Empty\()|⚠️|✔️|✔️|
|[MA0006](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0006.md)|用法|使用 String.Equals 而不是相等运算符|⚠️|✔️|✔️|
|[MA0007](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0007.md)|样式|在最后一个值后添加逗号|ℹ️|✔️|✔️|
|[MA0008](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0008.md)|性能|添加 StructLayoutAttribute|⚠️|✔️|✔️|
|[MA0009](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0009.md)|安全性|添加正则表达式计算超时|⚠️|✔️|❌|
|[MA0010](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0010.md)|设计|使用 AttributeUsageAttribute 标记特性|⚠️|✔️|✔️|
|[MA0011](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0011.md)|用法|缺少 IFormatProvider|⚠️|✔️|✔️|
|[MA0012](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0012.md)|设计|不要引发保留的异常类型|⚠️|✔️|❌|
|[MA0013](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0013.md)|设计|类型不应扩展 System.ApplicationException|⚠️|✔️|❌|
|[MA0014](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0014.md)|设计|不要引发 System.ApplicationException 类型|⚠️|✔️|❌|
|[MA0015](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0015.md)|用法|在 ArgumentException 中指定参数名|⚠️|✔️|❌|
|[MA0016](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0016.md)|设计|优先使用集合抽象而不是实现|⚠️|✔️|❌|
|[MA0017](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0017.md)|设计|抽象类型不应具有 public 或 internal 构造函数|⚠️|✔️|✔️|
|[MA0018](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0018.md)|设计|不要在泛型类型上声明静态成员(已弃用;请改用 CA1000)|ℹ️|✔️|❌|
|[MA0019](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0019.md)|用法|使用 EventArgs.Empty|⚠️|✔️|✔️|
|[MA0020](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0020.md)|性能|使用直接方法而不是 LINQ 方法|ℹ️|✔️|✔️|
|[MA0021](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0021.md)|用法|使用 StringComparer.GetHashCode 而不是 string.GetHashCode|⚠️|✔️|✔️|
|[MA0022](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0022.md)|设计|返回 Task.FromResult 而不是返回 null|⚠️|✔️|✔️|
|[MA0023](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0023.md)|性能|添加 RegexOptions.ExplicitCapture|⚠️|✔️|✔️|
|[MA0024](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0024.md)|用法|尽可能使用显式 StringComparer|⚠️|✔️|✔️|
|[MA0025](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0025.md)|设计|实现功能而不是抛出 NotImplementedException|⚠️|✔️|❌|
|[MA0026](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)|设计|修复 TODO 注释|⚠️|✔️|❌|
|[MA0027](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0027.md)|用法|优先隐式重新抛出异常|⚠️|✔️|✔️|
|[MA0028](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0028.md)|性能|优化 StringBuilder 用法|ℹ️|✔️|✔️|
|[MA0029](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0029.md)|性能|组合 LINQ 方法|ℹ️|✔️|✔️|
|[MA0030](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0030.md)|性能|移除无用的 OrderBy 调用|⚠️|✔️|✔️|
|[MA0031](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0031.md)|性能|优化 Enumerable.Count() 用法|ℹ️|✔️|✔️|
|[MA0032](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0032.md)|用法|使用带有 CancellationToken 参数的重载,即使作用域中没有可用的 token|ℹ️|❌|❌|
|[MA0033](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0033.md)|设计|不要使用 ThreadStaticAttribute 标记实例字段|⚠️|✔️|❌|
|[MA0035](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0035.md)|用法|不要使用危险的线程方法|⚠️|✔️|❌|
|[MA0036](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0036.md)|设计|将类设为静态|ℹ️|✔️|✔️|
|[MA0037](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0037.md)|用法|移除空语句|❌|✔️|✔️|
|[MA0038](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0038.md)|设计|将方法设为静态(已弃用,请改用 CA1822)|ℹ️|✔️|✔️|
|[MA0039](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0039.md)|安全性|不要编写自己的证书验证方法|❌|✔️|❌|
|[MA0040](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0040.md)|用法|将 CancellationToken 参数转发给接受它的方法|ℹ️|✔️|✔️|
|[MA0041](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0041.md)|设计|将属性设为静态(已弃用,请改用 CA1822)|ℹ️|✔️|✔️|
|[MA0042](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0042.md)|设计|当调用方法是 async 时不要使用阻塞调用|ℹ️|✔️|✔️|
|[MA0043](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0043.md)|用法|在 ArgumentException 中使用 nameof 运算符|ℹ️|✔️|✔️|
|[MA0044](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0044.md)|性能|移除无用的 ToString 调用|ℹ️|✔️|✔️|
|[MA0045](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0045.md)|设计|不要使用阻塞调用,即使调用方法必须变为 async|ℹ️|❌|✔️|
|[MA0046](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0046.md)|设计|使用 EventHandler\ 声明事件|⚠️|✔️|❌|
|[MA0047](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0047.md)|设计|在命名空间中声明类型|⚠️|✔️|❌|
|[MA0048](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0048.md)|设计|文件名必须与类型名匹配|⚠️|✔️|❌|
|[MA0049](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0049.md)|设计|类型名不应与包含命名空间匹配|❌|✔️|❌|
|[MA0050](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0050.md)|设计|在迭代器方法中正确验证参数|ℹ️|✔️|✔️|
|[MA0051](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0051.md)|设计|方法过长|⚠️|✔️|❌|
|[MA0052](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0052.md)|性能|将常量 Enum.ToString 替换为 nameof|ℹ️|✔️|✔️|
|[MA0053](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0053.md)|设计|将类或记录设为 sealed|ℹ️|✔️|✔️|
|[MA0054](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0054.md)|设计|将捕获的异常作为 innerException 嵌入|⚠️|✔️|✔️|
|[MA0055](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0055.md)|设计|不要使用终结器|⚠️|✔️|❌|
|[MA0056](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0056.md)|设计|不要在构造函数中调用可重写的成员|⚠️|✔️|❌|
|[MA0057](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0057.md)|命名|类名应以 'Attribute' 结尾|ℹ️|✔️|✔️|
|[MA0058](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0058.md)|命名|类名应以 'Exception' 结尾|ℹ️|✔️|✔️|
|[MA0059](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0059.md)|命名|类名应以 'EventArgs' 结尾|ℹ️|✔️|✔️|
|[MA0060](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0060.md)|设计|未使用 Stream.Read/Stream.ReadAsync 返回的值|⚠️|✔️|❌|
|[MA0061](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0061.md)|设计|方法重写不应更改默认值|⚠️|✔️|✔️|
|[MA0062](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0062.md)|设计|非标志枚举不应使用 "FlagsAttribute" 标记|⚠️|✔️|✔️|
|[MA0063](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0063.md)|性能|在 OrderBy 之前使用 Where|ℹ️|✔️|✔️|
|[MA0064](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0064.md)|设计|避免锁定公开可访问的实例|⚠️|✔️|❌|
|[MA0065](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0065.md)|性能|结构相等使用了默认的 ValueType.Equals 或 HashCode|⚠️|✔️|❌|
|[MA0066](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0066.md)|性能|在哈希表中使用了不友好的哈希表类型|⚠️|✔️|❌|
|[MA0067](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0067.md)|设计|使用 Guid.Empty|ℹ️|✔️|✔️|
|[MA0068](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0068.md)|设计|可空特性的参数名无效|⚠️|✔️|❌|
|[MA0069](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0069.md)|设计|非常量静态字段不应可见|⚠️|✔️|❌|
|[MA0070](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0070.md)|设计|过时的特性应包含解释说明|⚠️|✔️|❌|
|[MA0071](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0071.md)|样式|避免使用冗余的 else|ℹ️|✔️|✔️|
|[MA0072](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0072.md)|设计|不要在 finally 块中抛出异常|⚠️|✔️|❌|
|[MA0073](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0073.md)|样式|避免与布尔常量进行比较|ℹ️|✔️|✔️|
|[MA0074](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0074.md)|用法|避免隐式区域性敏感方法|⚠️|✔️|✔️|
|[MA0075](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0075.md)|设计|不要使用隐式区域性敏感的 ToString|ℹ️|✔️|❌|
|[MA0076](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0076.md)|设计|不要在内插字符串中使用隐式区域性敏感的 ToString|ℹ️|✔️|✔️|
|[MA0077](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0077.md)|设计|提供 Equals(T) 的类应实现 IEquatable\|⚠️|✔️|✔️|
|[MA0078](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0078.md)|性能|使用 'Cast' 而不是 'Select' 进行类型转换|ℹ️|✔️|✔️|
|[MA0079](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0079.md)|用法|使用 .WithCancellation() 转发 CancellationToken|ℹ️|✔️|✔️|
|[MA0080](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0080.md)|用法|使用 .WithCancellation() 的取消令牌|ℹ️|❌|❌|
|[MA0081](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0081.md)|设计|方法重写不应省略 params 关键字|⚠️|✔️|✔️|
|[MA0082](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0082.md)|设计|NaN 不应用于比较|⚠️|✔️|✔️|
|[MA0083](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0083.md)|设计|ConstructorArgument 参数应存在于构造函数中|⚠️|✔️|❌|
|[MA0084](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0084.md)||局部变量不应隐藏其他符号|⚠️|✔️|❌|
|[MA0085](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0085.md)|用法|不应使用匿名委托从事件中取消订阅|⚠️|✔️|❌|
|[MA0086](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0086.md)|设计|不要在终结器中抛出异常|⚠️|✔️|❌|
|[MA0087](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0087.md)|设计|带有 \[DefaultParameterValue\] 特性的参数也应标记为 \[Optional\]|⚠️|✔️|✔️|
|[MA0088](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0088.md)|设计|使用 \[DefaultParameterValue\] 而不是 \[DefaultValue\]|⚠️|✔️|✔️|
|[MA0089](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0089.md)|性能|优化字符串方法的使用|ℹ️|✔️|✔️|
|[MA0090](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0090.md)|设计|移除空的 else/finally 块|ℹ️|✔️|✔️|
|[MA0091](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0091.md)|用法|实例事件的发送者应为 'this'|⚠️|✔️|✔️|
|[MA0092](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0092.md)|用法|静态事件的发送者应为 'null'|⚠️|✔️|❌|
|[MA0093](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0093.md)|用法|引发事件时 EventArgs 不应为 null|⚠️|✔️|✔️|
|[MA0094](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0094.md)|设计|提供 CompareTo(T) 的类应实现 IComparable\|⚠️|✔️|✔️|
|[MA0095](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0095.md)|设计|实现 IEquatable\ 的类应重写 Equals(object)|⚠️|✔️|✔️|
|[MA0096](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0096.md)|设计|实现 IComparable\ 的类也应实现 IEquatable\|⚠️|✔️|✔️|
|[MA0097](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0097.md)|设计|实现 IComparable\ 或 IComparable 的类应重写比较运算符|⚠️|✔️|✔️|
|[MA0098](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0098.md)|性能|使用索引器而不是 LINQ 方法|ℹ️|✔️|✔️|
|[MA0099](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0099.md)|用法|使用显式枚举值而不是 0|⚠️|✔️|✔️|
|[MA0100](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0100.md)|用法|在释放资源前 await 任务|⚠️|✔️|❌|
|[MA0101](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0101.md)|用法|字符串包含隐式行尾字符|👻|✔️|✔️|
|[MA0102](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0102.md)|设计|将成员设为 readonly|ℹ️|✔️|✔️|
|[MA0103](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0103.md)|用法|使用 SequenceEqual 而不是相等运算符|⚠️|✔️|✔️|
|[MA0104](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0104.md)|设计|不要创建具有 BCL 名称的类型|⚠️|❌|❌|
|[MA0105](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0105.md)|性能|使用 lambda 参数而不是使用闭包|ℹ️|✔️|✔️|
|[MA0106](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0106.md)|性能|通过使用带有 'factoryArgument' 参数的重载来避免闭包|ℹ️|✔️|✔️|
|[MA0107](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0107.md)|设计|不要使用 object.ToString|ℹ️|❌|❌|
|[MA0108](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0108.md)|用法|移除冗余的参数值|ℹ️|✔️|✔️|
|[MA0109](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0109.md)|设计|考虑添加带有 Span\ 或 Memory\ 的重载|ℹ️|❌|❌|
|[MA0110](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0110.md)|性能|使用 Regex 源生成器|ℹ️|✔️|✔️|
|[MA0111](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0111.md)|性能|使用 string.Create 而不是 FormattableString|ℹ️|✔️|✔️|
|[MA0112](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0112.md)|性能|使用 'Count \> 0' 而不是 'Any()'|ℹ️|❌|✔️|
|[MA0113](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0113.md)|设计|使用 DateTime.UnixEpoch|ℹ️|✔️|✔️|
|[MA0114](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0114.md)|设计|使用 DateTimeOffset.UnixEpoch|ℹ️|✔️|✔️|
|[MA0115](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0115.md)|用法|未知的组件参数|⚠️|✔️|❌|
|[MA0116](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0116.md)|设计|带有 \[SupplyParameterFromQuery\] 特性的参数也应标记为 \[Parameter\]|⚠️|✔️|✔️|
|[MA0117](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0117.md)|设计|带有 \[EditorRequired\] 特性的参数也应标记为 \[Parameter\]|⚠️|✔️|✔️|
|[MA0118](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0118.md)|设计|\[JSInvokable\] 方法必须是 public 的|⚠️|✔️|✔️|
|[MA0119](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0119.md)|设计|不得在 OnInitialized 或 OnInitializedAsync 中使用 JSRuntime|⚠️|✔️|❌|
|[MA0120](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0120.md)|性能|当未使用返回值时使用 InvokeVoidAsync|ℹ️|✔️|✔️|
|[MA0121](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0121.md)|设计|不要覆盖参数值|ℹ️|❌|❌|
|[MA0122](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0122.md)|设计|带有 \[SupplyParameterFromQuery\] 特性的参数仅在可路由组件 (@page) 中有效|ℹ️|✔️|❌|
|[MA0123](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0123.md)|设计|序列号必须是常量|⚠️|✔️|❌|
|[MA0124](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0124.md)|设计|Microsoft.Extensions.Logging 参数类型无效|⚠️|✔️|❌|
|[MA0125](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0125.md)|设计|日志参数类型列表包含无效类型|⚠️|✔️|❌|
|[MA0126](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0126.md)|设计|日志参数类型列表包含重复项|⚠️|✔️|❌|
|[MA0127](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0127.md)|用法|使用 String.Equals 而不是 is 模式|👻|✔️|✔️|
|[MA0128](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0128.md)|用法|使用 'is' 运算符而不是 SequenceEqual|ℹ️|✔️|✔️|
|[MA0129](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0129.md)|用法|在 using 语句中 await 任务|⚠️|✔️|✔️|
|[MA0130](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0130.md)|用法|GetType() 不应用于 System.Type 实例|⚠️|✔️|❌|
|[MA0131](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0131.md)|用法|ArgumentNullException.ThrowIfNull 不应用于不可空类型|⚠️|✔️|✔️|
|[MA0132](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0132.md)|设计|不要隐式转换为 DateTimeOffset|⚠️|✔️|❌|
|[MA0133](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0133.md)|设计|使用 DateTimeOffset 而不是依赖隐式转换|ℹ️|✔️|❌|
|[MA0134](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0134.md)|用法|观察异步调用的结果|⚠️|✔️|❌|
|[MA0135](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0135.md)|设计|日志参数没有配置类型|⚠️|❌|❌|
|[MA0136](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0136.md)|用法|原始字符串包含隐式行尾字符|👻|✔️|❌|
|[MA0137](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0137.md)|设计|当方法返回可等待类型时使用 'Async' 后缀|⚠️|❌|✔️|
|[MA0138](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0138.md)|设计|当方法不返回可等待类型时不要使用 'Async' 后缀|⚠️|❌|✔️|
|[MA0139](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0139.md)|设计|Serilog 参数类型无效|⚠️|✔️|❌|
|[MA0140](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0140.md)|设计|if 和 else 分支具有相同的代码|⚠️|✔️|❌|
|[MA0141](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0141.md)|用法|使用 'is not null' 而不是 '!= null'|ℹ️|❌|✔️|
|[MA0142](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0142.md)|用法|使用 'is null' 而不是 '== null'|ℹ️|❌|✔️|
|[MA0143](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0143.md)|设计|主构造函数参数应为 readonly|⚠️|✔️|❌|
|[MA0144](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0144.md)|性能|使用 System.OperatingSystem 检查当前操作系统|⚠️|✔️|✔️|
|[MA0145](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0145.md)|用法|\[UnsafeAccessorAttribute\] 方法的签名无效|⚠️|✔️|❌|
|[MA0146](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0146.md)|用法|必须在局部函数上显式设置名称|⚠️|✔️|✔️|
|[MA0147](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0147.md)|用法|避免为委托使用 async void 方法|⚠️|✔️|❌|
|[MA0148](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0148.md)|用法|常量值请使用 'is' 模式而不是 '=='|ℹ️|❌|✔️|
|[MA0149](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0149.md)|用法|常量值请使用 'is not' 模式而不是 '!='|ℹ️|❌|✔️|
|[MA0150](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0150.md)|设计|当类型回退到 object.ToString() 时不要调用 ToString()|⚠️|✔️|❌|
|[MA0151](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0151.md)|用法|DebuggerDisplay 必须包含有效的成员|⚠️|✔️|❌|
|[MA0152](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0152.md)|性能|使用 Unwrap 而不是使用两次 await|ℹ️|✔️|✔️|
|[MA0153](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0153.md)|设计|不要直接记录使用 DataClassificationAttribute 修饰的符号|⚠️|✔️|❌|
|[MA0154](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0154.md)|设计|在 XML 注释中使用 langword|ℹ️|✔️|✔️|
|[MA0155](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0155.md)|设计|不要使用 async void 方法|⚠️|❌|❌|
|[MA0156](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0156.md)|设计|当方法返回 IAsyncEnumerable\ 时使用 'Async' 后缀|⚠️|❌|✔️|
|[MA0157](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0157.md)|设计|当方法返回 IAsyncEnumerable\ 时不要使用 'Async' 后缀|⚠️|❌|✔️|
|[MA0158](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0158.md)|性能|使用 System.Threading.Lock|⚠️|✔️|✔️|
|[MA0159](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0159.md)|性能|使用 'Order' 而不是 'OrderBy'|ℹ️|✔️|✔️|
|[MA0160](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0160.md)|性能|使用 ContainsKey 而不是 TryGetValue|ℹ️|✔️|✔️|
|[MA0161](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0161.md)|用法|必须显式设置 UseShellExecute|ℹ️|❌|✔️|
|[MA0162](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0162.md)|用法|使用带有 ProcessStartInfo 的 Process.Start 重载|ℹ️|❌|❌|
|[MA0163](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0163.md)|用法|重定向标准输入或输出时 UseShellExecute 必须为 false|⚠️|✔️|❌|
|[MA0164](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0164.md)|样式|使用括号使 not 模式更清晰|⚠️|✔️|✔️|
|[MA0166](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0166.md)|用法|将 TimeProvider 转发给接受它的方法|ℹ️|✔️|✔️|
|[MA0167](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0167.md)|用法|使用带有 TimeProvider 参数的重载|ℹ️|❌|❌|
|[MA0168](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0168.md)|性能|对 in 或 ref readonly 参数使用 readonly struct|ℹ️|❌|❌|
|[MA0169](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0169.md)|设计|使用 Equals 方法而不是运算符|⚠️|✔️|✔️|
|[MA0170](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0170.md)|设计|类型不能用作特性参数|⚠️|❌|❌|
|[MA0171](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0171.md)|用法|使用 'is' / 'is not null' 而不是 Nullable\.HasValue|ℹ️|❌|✔️|
|[MA0172](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0172.md)|用法|逻辑运算的两侧相同|⚠️|❌|❌|
|[MA0173](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0173.md)|设计|使用 LazyInitializer.EnsureInitialize|ℹ️|✔️|✔️|
|[MA0174](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0174.md)|样式|记录应使用显式的 'class' 关键字|ℹ️|❌|✔️|
|[MA0175](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0175.md)|样式|记录不应使用显式的 'class' 关键字|ℹ️|❌|✔️|
|[MA0176](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0176.md)|性能|优化 guid 创建|ℹ️|✔️|✔️|
|[MA0177](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0177.md)|样式|尽可能使用单行 XML 注释语法|ℹ️|❌|✔️|
|[MA0178](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0178.md)|设计|使用 TimeSpan.Zero 而不是 TimeSpan.FromXXX(0)|ℹ️|✔️|✔️|
|[MA0179](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0179.md)|性能|使用 Attribute.IsDefined 而不是 GetCustomAttribute(s)|ℹ️|✔️|✔️|
|[MA0180](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0180.md)|设计|ILogger 类型参数应与包含类型匹配|⚠️|❌|✔️|
|[MA0181](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0181.md)|样式|不要使用强制转换|ℹ️|❌|❌|
|[MA0182](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0182.md)|设计|避免未使用的内部类型|ℹ️|✔️|✔️|
|[MA0183](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0183.md)|用法|格式字符串应使用占位符|⚠️|✔️|❌|
|[MA0184](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0184.md)|样式|不要使用不带参数的内插字符串|👻|✔️|✔️|
|[MA0185](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0185.md)|性能|当所有参数都 invariant 于区域性时简化 string.Create|ℹ️|✔️|✔️|
|[MA0186](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0186.md)|设计|Equals 方法应在参数上使用 \[NotNullWhen(true)\]|ℹ️|❌|✔️|
|[MA0187](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0187.md)|设计|使用构造函数注入而不是 \[Inject\] 特性|ℹ️|❌|✔️|
|[MA0188](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0188.md)|设计|使用 System.TimeProvider 而不是自定义的时间抽象|ℹ️|✔️|❌|
|[MA0189](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0189.md)|设计|使用 InlineArray 而不是固定大小的缓冲区|ℹ️|✔️|✔️|
|[MA0190](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0190.md)|设计|对 GeneratedRegex 使用分部属性而不是分部方法|ℹ️|✔️|✔️|
|[MA0191](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0191.md)|设计|不要使用 null 包容运算符|⚠️|❌|❌|
|[MA0192](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0192.md)|用法|使用 HasFlag 而不是按位检查|ℹ️|❌|✔️|
|[MA0193](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0193.md)|用法|使用带有 MidpointRounding 参数的重载|ℹ️|✔️|✔️|
|[MA0194](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0194.md)|用法|合并对同一值的 is 表达式|ℹ️|✔️|✔️|
# 抑制规则
|Id|抑制的规则|理由|
|--|---------------|-------------|
|`MAS0001`|[CA1822](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822?WT.mc_id=DT-MVP-5003978)|在使用 BenchmarkDotNet 特性修饰的方法上抑制 CA1822。|
|`MAS0002`|[CA1822](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822?WT.mc_id=DT-MVP-5003978)|在使用 System.Text.Json 特性(如 \[JsonPropertyName\] 或 \[JsonInclude\])修饰的方法上抑制 CA1822。|
|`MAS0003`|[IDE0058](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0058?WT.mc_id=DT-MVP-5003978)|对已知类型抑制 IDE0058|
|`MAS0004`|[CA1507](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1507?WT.mc_id=DT-MVP-5003978)|在使用 \[Newtonsoft.Json.JsonPropertyAttribute\] 修饰的方法上抑制 CA1507。|
# 重构
|名称|
|----|
|`ConvertToStringFormat`|
|`MakeInterpolatedString`|
# 配置
您可以设置 `` MSBuild 属性来配置规则的默认严重程度。默认值为 `Default`。您可以将其设置为 `None` 以默认禁用所有规则。
```
None
```
标签:AI辅助编程, Bug检测, LNA, macOS, Meziantou.Analyzer, NuGet包, Roslyn, SOC Prime, URL发现, 代码审查, 代码规范, 多人体追踪, 安全专业人员, 安全检测, 开发工具, 最佳实践, 编译器, 自动修复, 错误基检测, 静态代码分析, 静态分析器