Sometimes it can be confusing reading code in instance members that refers to other instance members of the same class (or a base class):
public void MyMethod()
{
Where = did + AllTheseWeirdThings(GetDeclared()); // ?
}
Having a coding standard something like "prefix all private/protected members with "_" doesn't help, because instance members can still refer to public members.
It would be much better to read this:
public void MyMethod()
{
this.Where = this.did + base.AllTheseWeirdThings(this.GetDeclared()); // ?
}
Is there a way to enforce this, either with compiler options, StyleCop, or something similar?
There's no compiler option that enforces your rule.
However, a cursory Google search brings up this StyleCop rule: http://www.thewayithink.co.uk/stylecop/sa1101.htm
ReSharper has a similar option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With