コードインスペクション:拡張メソッドを拡張機能ブロックに変換
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;
}
}
}
2026 年 6 月 12 日