Changes to the P?Type? Template in CodeRush 11.1

Our previous posts on the New Contexts, the New StringProviders and the New Goto TextCommand in CodeRush 11.1 are obviously useful in their own right, but as hinted at they also come together to contribute to an upgrade to the standard p?Type? template.

The p?Type? template now emits any backing fields together in a single region. This renders the code easier to read, making it simpler to understand and maintain.

Consider the code expansion generated with the previous version of the p?Type? template…

pType10_2

As you can see, each field generated for backing store is placed next to the property that accesses it. This can be useful for grouping by function, but it can lead to code which is harder to read. Fields that are distributed in this way can be harder to locate are easily skipped over when scanning through code. We’ve long been asked for a way to group all te generated fields together in one place.

The new implementation of the p?Type? does exactly that, navigating to the first field in the type, injecting the field in this location and then returning to finish emitting the property at the location originally picked by the user.

pType11_1

I think you’ll agree it’s also a lot easier on the eyes.

9 comment(s)
Jim Foye
Jim Foye

I agree. Though I see the "sprinkle the field declarations through the class" approach a lot, I find it makes it difficult to get a quick sense of what the class is and does.

6 June, 2011
Michael Proctor [DX-Squad]
Michael Proctor [DX-Squad]

That is great Rory, however what about all those classes we already have, is there a "Class Cleaner" *cough* ;)

I currently use ClassCleaner plugin to acheive this functionality, however it would be nice to use the CodeRush configured Groups instead of the defined groups within the Plugin.

Any tips?

6 June, 2011
Michael Proctor [DX-Squad]
Michael Proctor [DX-Squad]

Also another quick question, I note this is only using a Comment as an "anchor".

Would it not be possible to add a flag in the options to say use "Regions" instead? (again... like ClassCleaner ;))

7 June, 2011
Przemyslaw Wlodarczak
Przemyslaw Wlodarczak

Rory, these changes made to templates are great. Sadly, other parts of CR+R! are left behind. Some of available refactorings and code providers still place generated fields the old way - e.g. "Convert To Property With Backing Store"

7 June, 2011
Rory Becker - DevExpress
Rory Becker - DevExpress

@Michael Re: Code Cleanup... funny you should mention that... We do have a code cleanup this release.

Overview details here (www.devexpress.com/.../index.xml), but I believe Mark will be elaborating on it in an upcoming post. However I do not believe we have a specific cleanup to provide this feature. Perhaps add a request? http://www.devexpress.com/sc/

@Michael Re: use regions. The feature doesn't really use the comment as an anchor, but places the configurable string in place, only if there are no pre existing fields.

Details on configuring this feature are available here -> community.devexpress.com/.../new-stringproviders-in-coderush-11-1.aspx

...and yes by setting the header and footer appropriately, you can change this into a region. (I'm going to be doing exactly this. :)

@Przemyslaw Yes you are correct. I'm sure we will be updating these refactoring to provide this facility in the near future. Although a little nudge would surely help :) http://www.devexpress.com/sc/

7 June, 2011
Przemyslaw Wlodarczak
Przemyslaw Wlodarczak
7 June, 2011
Serge (DevExpress Support)
Serge (DevExpress Support)

We have decided to introduce a new option to control this behavior:

www.devexpress.com/.../S37570.aspx

10 June, 2011
Jim Foye
Jim Foye

I am using 11.1.6.0 and not seeing the new behavior. Am I missing something?

23 July, 2011
Rory Becker - DevExpress
Rory Becker - DevExpress

Templates are not upgraded automatically. This is to prevent damage to custom templates etc

See my post on Merging CodeRush Templates (community.devexpress.com/.../merging-coderush-templates-via-export-and-import.aspx)

23 July, 2011

Please login or register to post comments.