コードインスペクション:拡張メソッドを拡張機能ブロックに変換する
C# 14 では、拡張メソッドを宣言する新しい方法として 拡張機能ブロックが導入されており、同じ拡張対象型に対して複数のメソッドをエレガントに宣言できます。 そのため、ReSharper は同じ拡張対象型をターゲットとする複数の既存の拡張メソッドを単一の 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 日