Leon Meijer's Weblog

About my personal life, technology and business/work related...
posts - 129, comments - 334, trackbacks - 0

Creating a CodeRush Code Template for a XAF property

This is a follow-up of my previous post about CodeRush/XAF tricks. Where the previous post was about Intelligent Paste, this one describes how to create a Code Template.

The CodeRush engine behind the Code Templates is continuously watching which keystrokes you type. If the strokes match with a template, it will auto complete your code.

For example, if you move the cursor to the first line in a class and type 'p <spacebar>', it will show you the following:

image

The code editor is now interactive and you can customize the type, member variable and property name by pressing the TAB-key. Pressing 'string<TAB-key>Name' gives you:

image

As you can see, the Code Template followed a coding standard of adding an underscore prefix to the member variable and it updated the get and set implementations. Isn't that cool!

Creating a Code Template for XAF domain objects

Like I mentioned before in my previous post, properties in XAF domain objects and XPO persistent objects require a customized set-clause implementation.

Here are the steps:

  • In Visual Studio, go to the DevExpress menu and choose Options...
  • In the dropdown box next to the label Level, select Advanced;
  • Go to /Editor/Templates or type Templates in the search box;
  • In the search box below the large text Templates, go to the Search text box and type p. It should select the p-item hierarchically below the 1-key;
  • Right-click the item p from the list and choose Duplicate
  • In the Expansion text box, type:
«?Set(Type,String)»«:#PropertyVarDeclaration#»
«:#PropertyDefaultScope#»«Caret»«:#PropertyTypeField#»«BlockAnchor» «:#PropertyName#»
{
     get {     return «:#PropertyVar#»; }
     set { «:#PropertyVar#» = value;     SetPropertyValue("«:#PropertyName#»", ref «:#PropertyVar#», value);}
}«Target»
  • In the list named Use:, scroll down till XAF Business Class. Click on the check box until it gets a green check mark;
  • Back to the list where you duplicated p, select the original p (the one you duplicated)
  • In the list named Use:, scroll down till XAF Business Class. Click on the check box until it gets a red check mark;
  • See the screen shot below

image

  • Press OK in the Options dialog

Okay, now off course we want to play with this. If you have a XAF license, go to or create a XAF application and add a Domain Object.

If you now type 'p <spacebar>', you will get a fully implemented property (and member variable declaration) which is compatible with XAF and XPO. See the screen shot below.

image

Hope this helps,

Leon

Print | posted on Saturday, November 22, 2008 6:49 PM |

Powered by: