コードインスペクション:拡張機能ブロックに移動
C# 14 では、 拡張機能ブロックが導入され、拡張メソッドを宣言する新しい方法です。同じ拡張対象型に対して複数のメソッドを宣言する洗練された方法です。 したがって、JetBrains Rider は、特定のターゲット型に対する拡張メソッドを、そのターゲット型に対応する extension ブロックに移動することを提案します。 例えば:
public static class StringExtensions
{
extension(string str)
{
public bool IsNullOrEmpty()
{
return string.IsNullOrEmpty(str);
}
public bool IsNullOrWhiteSpace()
{
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 日