JetBrains Rider 2025.3 Help

代码检查:将扩展方法转换为扩展块

C# 14 引入了 扩展块 ,作为声明扩展方法的一种新方式。这是一种为同一扩展类型声明多个方法的优雅方式。 因此,JetBrains Rider 建议将针对同一扩展类型的多个现有扩展方法转换为一个 extension 块。

public static class StringExtensions { public static bool IsNullOrEmpty(this string str) { return string.IsNullOrEmpty(str); } public static bool IsNullOrWhiteSpace(this string str) { return string.IsNullOrWhiteSpace(str); } public static string TrimStart(this string str, string prefix) { if (str.StartsWith(prefix)) return str.Substring(prefix.Length); return str; } }
public static class StringExtensions { extension(string str) { public bool IsNullOrEmpty() { return string.IsNullOrEmpty(str); } public bool IsNullOrWhiteSpace() { return string.IsNullOrWhiteSpace(str); } public string TrimStart(string prefix) { if (str.StartsWith(prefix)) return str.Substring(prefix.Length); return str; } } }
最后修改日期: 2025年 12月 5日