This rule enforces the correct usage of the TSelf parameter in C#. When implementing an interface that requires a TSelf type parameter, such as IParsable<TSelf>, the TSelf parameter should be the same as the type that is implementing the interface. This is important because it ensures type safety and allows for correct usage of the interface’s methods.
In the non-compliant code example, the class MyDate is implementing the IParsable<TSelf> interface but is using DateOnly for the TSelf parameter. This is incorrect because the TSelf parameter should be MyDate, the type that is implementing the interface.
To avoid violating this rule, always use the type that is implementing the interface for the TSelf parameter.
Non-Compliant Code Examples
usingSystem;// The 'IParsable<TSelf>' requires the 'TSelf' type parameter to be filled with the derived type 'MyDate'publicreadonlystructMyDate:IParsable<DateOnly>{}