Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 682 Bytes

File metadata and controls

37 lines (28 loc) · 682 Bytes

CSL1013: Change extension function to extension member.

(This feature is available starting in .NET 10)

An old-style extension function can be seamlessly converted to a new style extension member, as follow:

// Before
public static int GetLength(this string s)
{
    ArgumentNullException.ThrowIfNull(s);

    return s.Length;
}

// After
extension(string s)
{
    public int GetLength()
    {
        ArgumentNullException.ThrowIfNull(s);

        return s.Length;
    }
}

Sample code

public static int GetLength(this string s) // CSL1013: Change 'GetLength' to an extension member.
{
    ArgumentNullException.ThrowIfNull(s);

    return s.Length;
}