The 'this' keyword, chained methods and readability.

Hello,

I generally don't use the 'this' keyword because I'm using underscores for variables by convention however sometimes it make sense to keep it when chaining methods, here is an example.

public FakeAssemblyBuilder()
{
     _resources = new Dictionary<string, Stream>();

     this.SetCodeBase(DEFAULT_ASSEMBLY_NAME)
           .SetLocation(DEFAULT_ASSEMBLY_NAME)
           .SetTypes(new Type[] { });
}

public FakeAssemblyBuilder()
{
     _resources = new Dictionary<string, Stream>();

     SetCodeBase(DEFAULT_ASSEMBLY_NAME)
          .SetLocation(DEFAULT_ASSEMBLY_NAME)
          .SetTypes(new Type[] { });
}


I find the former more readable (even though it's not immediately obvious in this post) so I wonder whether you can add a minor option that will remove the keyword on anything except when chaining methods?

2 comments
Comment actions Permalink

Hi,

ReSharper can force or not force this qualifier using Code Cleanup profiles (ReSHarper | Options | Tools | Code Cleanup), however there are no specific settings to add (or not to add) this qualifier in any specific cases, unfortunately.

Thank you.

0
Comment actions Permalink

Yeah, I know that but I'm just wondering whether you can add it as an option. :)

0

Please sign in to leave a comment.