Leon Meijer's Weblog

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

CodeRush Intelligent Paste for a Property within a XAF Domain Object

If you have installed Developer Express' CodeRush plugin within Visual Studio, you'd probably already know the Intelligent Paste feature. If you don't, let me briefly explain it to you.

The Intelligent Paste let you auto generate the C#/VB.NET code for a property which accesses a member variable. For example, you type:

   1: private string _Name;

 

You select and copy the line to your clipboard and paste it wherever you like. Instead of pasting it 1:1, it replaces the text with the generated property. Like this:

   1:         public string Name
   2:         {
   3:             get { return _Name; }
   4:             set { SetPropertyValue<string>("Name", ref _Name, value); }
   5:         }

 

Because I'm currently building an application on top of the eXpressAppFramework, I required a Intelligent Paste template that generates properties that will function with the framework's object-relational mapper XPO. XPO requires a customized set-clause with a call to the SetPropertyValue method to flag that an object has been modified (and has to be updated in a DBMS).

Ok, 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;
  • In the tree, go to /Editor/Clipboard/Intelligent Paste or type Intelligent Paste in the search box;
  • Select Property (prefixed field) from the list, right-click it and choose Duplicate;
  • Give the new template a name, like XPO Property (prefixed field);
  • In the Replacement text box, type:
public %StaticModifier1%%Type1% %PartialIdentifier1%
{ 
  get { return «Marker(60)»%FieldVarPrefix1%%PartialIdentifier1%; }
  set { SetPropertyValue<%Type1%>("«?PropertyNameFromField(%PartialIdentifier1%)»", ref %FieldVarPrefix1%%PartialIdentifier1%, value); }
}
  • In the list named Use:, scroll down till XAF Business Class. Click on the check box until it gets a green check mark;
  • See the screen shot below

image

  • Again select Property (prefixed field) from the list;
  • In the list named Use:, scroll down till XAF Business Class. Click on the check box until it gets a red check mark;
  • Do the same for the Property (prefixed readonly field)
  • Click OK
  • See the screen shot below
  • Press OK in the Options dialog

image

 

By selecting and excluding the XAF Business Class, you create a new Intelligent Paste template that will function only in the XAF classes that require custom property implementations. If you don't use XAF and would like to implement the same trick for XPO, select and exclude the In XPO Persistent Class instead.

 

Hope this helps,

Leon

Print | posted on Saturday, November 22, 2008 5:54 PM | Filed Under [ Technology .NET General ]

Powered by: