Dec
21
2009

CodeRush Is Your Best Friend for XPO

User Rating: / 5
PoorBest 

Recently Gary Short burnt a little too much midnight oil and ended up posting a blog with some incorrect property patterns for XPO. These have been corrected but it did make me wonder how many people are actually using the CodeRush templates for XPO.

So I decided to do up a quick blog to highlight some of the “cool” features of CodeRush with XPO. First thing to remember is that CodeRush is language independent, it is smart and knows how to code as a C# or VB.NET programmer, so if you enjoy your hieroglyphic  bracket hell {C#} or prefer to program in English (VB.NET) CodeRush will provide the code that you need.

Note: CodeRush will automatically put in the project reference to DevExpress libraries as well as a using/Imports statement as well :)

xc – XPO Persistent Class

Firstly you can declare a Persistent Class (inheriting XPObject) by using the template “xc”,

Public Class PersistentClass
    Inherits XPObject
    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
End Class

 

xp?type? – XPO Persistent Property

Declaring persistent properties are a breeze, for this example I have expanded a “xps” template

    Private _propertyName As String
    Public Property PropertyName() As String
        Get
            Return _propertyName
        End Get
        Set(ByVal Value As String)
            SetPropertyValue("PropertyName", _propertyName, Value)
        End Set
    End Property

 

xr?type? - XPO ReadOnly Persistent Property

These can be "tricky" to remember, the basic idea is you persist a private variable and only expose a readonly property which is "alias'd" to the persisted private variable. Using this template makes it very easy to setup a readonly persistent property, for an example here is a readonly String property

<Persistent("PropertyName")> _
Private _propertyName As String
Protected Overridable Sub SetPropertyName(ByVal Value As String)
    SetPropertyValue("PropertyName", _propertyName, Value)
End Sub
<PersistentAlias("_propertyName")> _
Public ReadOnly Property PropertyName() As String
    Get
        Return _propertyName
    End Get
End Property

 

xpa - XP Associated Persistent Property

Although not as "handy" as the others this will create a persistent property of type Object with the AssocationAttribute already on it. Note: this template hasn't got the ?type? style, so you can't do xpas for a string for example, it will create a property with the type set to Object, however CodeRush has linked types so if you change the type it will change the private variable, setter and property type all in one go.

Private _propertyName As Object
<Association("object-Class1s")> _
Public Property PropertyName() As Object
    Get
        Return _propertyName
    End Get
    Set(ByVal Value As Object)
        SetPropertyValue("PropertyName", _propertyName, Value)
    End Set
End Property

 

xpcl - XPO Associated Collection

Need an associated collection for a 1-to-Many or Many-to-Many, just expand xpcl and it will provide you with what you need

<Association("Class1-Relations")> _
Public ReadOnly Property Relations() As XPCollection(Of RelationType)
    Get
        Return GetCollection(Of RelationType)("Relations")
    End Get
End Property

 

CodeRush Background: Developer Express created CodeRush for Visual Studio® .NET to help developers and managers meet these increased demands for quality and functionality, by boosting productivity while eliminating the repetition that erodes precious creativity.

For Developers, CodeRush for Visual Studio® .NET will help you create sophisticated code blocks in seconds and extend code templates instantly. CodeRush will complete identifiers as you type and expand or contract selections logically. With CodeRush, you will be able to instantly place selected code inside Try/Catch blocks, Regions and your own custom wrappers with ease. You can even reverse the logic of selected code and revisit important points within your code instantly (and effortlessly swap between locations). http://www.devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/index.xml

Comments  

 
0 # Trevor Lane 2009-12-21 15:12
Thanks Michael,

I didn't know about xc or xr
Reply | Reply with quote | Quote
 
 
0 # Michael Proctor [Dx-Squad] 2009-12-21 15:31
Trevor,

I reckon xr is one of the handiest one as it can be "tricky" to setup a readonly Persistent Property, this just sets it up for you ready to "manipulate" into what you need.

Glad you found it informative. Spent a bit of time on my blog site over the last month, so now hopefully it means I can pump out these little blogs whenever I see something. you'll notice I also display VB.NET and C# to keep everyone happy ;)

Have a Merry Christmas.
Reply | Reply with quote | Quote
 

Add comment

Although I believe your free to say what you want, please don't abuse either myself or other peoples, be constructive.


Security code
Refresh

Should AussieALF stay bald?




Results

Latest Comments

My Twitter

Follow me on twitter