locked
How do I automatically remove "this." from my C# lines? RRS feed

  • Question


  •  What sort of addin do I need to make in order to process each C# line to remove the "this." from my code?

    We use code generation to add bindingsources with long descriptive names to our UI components. Sometimes the lines get a bit wide, and I want to automatically remove the "this." from a line with "this.bsWithReallyLongName.Position..." etc..

    The this. helps with choosing the correct bindingsource from the intellisense menu, but it takes up space and is unnecessary.

    Monday, August 25, 2008 8:32 PM

Answers

  • Hi

    I think you do not need to write your own addin for such a task. The (wonderful) ReSharper from JetBrains (http://www.jetbrains.com/resharper/) can reformat code (singe files and the whole solution) this way.

    Benjamin
    Monday, August 25, 2008 11:21 PM
  • Why not just use simple Find and Replace? Find "this."and replace it with "". If you are affraid that some class or member name can end with "this", use regular expressions for finding.

    Peter Macej, VSdocman - Commenter and generator of class documentation for C#, VB .NET and ASP .NET
    Tuesday, August 26, 2008 7:03 AM

All replies

  • Hi

    I think you do not need to write your own addin for such a task. The (wonderful) ReSharper from JetBrains (http://www.jetbrains.com/resharper/) can reformat code (singe files and the whole solution) this way.

    Benjamin
    Monday, August 25, 2008 11:21 PM
  • Why not just use simple Find and Replace? Find "this."and replace it with "". If you are affraid that some class or member name can end with "this", use regular expressions for finding.

    Peter Macej, VSdocman - Commenter and generator of class documentation for C#, VB .NET and ASP .NET
    Tuesday, August 26, 2008 7:03 AM
  • I think my question was more "what type of addin do I need to create" in order to parse the code in real time and do the find & replace?

    What type of addin provides a hook for parsing the code in real time? I've only seen tutorials for creating addins that are triggered when a user clicks a toolbar button or right clicks on the solution explorer etc...

    Thanks
    Friday, August 29, 2008 4:23 PM