This project is read-only.

Taking the pain out of MemberOrder attribute management for UI display

Jun 29, 2012 at 12:38 PM
Edited Aug 3, 2012 at 9:44 AM

Hi all
One pain point I have always had with Naked Objects is managing the MemberOrder attributes for the properties in the order I want them to appear on the UI. It is a huge schlep.
So last night I wrote a Visual Studio macro to help me with that. I thought I'd share it here for anybody else that might be interested.
Basically it looks for the Metadata class (the buddy class) and assigns an incrementing member order value to each subsequent member order attribute it finds.

The result is that the member order (UI display order) and the physical order of the properties in the buddy class are the same and can now always remain in sync.
Hence, I can now just rearrange the properties in my code, moving them up and down with cut and paste or drag and drop, then run my macro, and it will update the MemberOrder values to be in the same sequence.

I have assigned a hot key to to AssignMemberOrders, for easy execution.

This is a huge productivity boost for me personally, and will make a big difference for the domain I am starting to model now.

By default AssignMemberOrders uses an initial value of 1000, and increments by 10.
There is also AssignMemberOrdersPrompt, that will prompt you for the initial MemberOrder value to start with.

I will post updates here as I make refinements.
Also, I couldn't figure out how to write my macro in C#. Anybody know?

Below is the macro:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

' Disclaimer: Run this macro at your own risk. Don't come crying if it stuffs up your source code.
Public Module MemberOrder
    Dim order As Integer
    Dim marker As String

    Public Sub AssignMemberOrders()
    End Sub

    Public Sub AssignMemberOrdersPrompt()
        Dim initialOrder As Integer = InputBox("Enter the initial Member Order value")
    End Sub

    Public Sub AssignMemberOrders(ByVal initialOrder As Integer)
        order = initialOrder

        marker = "##temp member order reorder marker##"
        'Get the selected text
        Dim sel As TextSelection
        sel = DTE.ActiveDocument.Selection

        sel.Text = marker

        If (FindBeginningOfMetadataClass(sel)) Then
            While (FindAndApplyNextMemberOrder(sel))
            End While
        End If

        ' Remove marker and return cursor to original position in document.
        sel.Text = ""
    End Sub

    Public Function FindBeginningOfMetadataClass(ByVal sel As TextSelection) As Boolean
        Return sel.FindPattern("public class +.@_Metadata", vsFindOptions.vsFindOptionsRegularExpression)
    End Function

    Public Function FindAndApplyNextMemberOrder(ByVal sel As TextSelection) As Boolean
        If (Not sel.FindPattern("MemberOrder *\([0-9]+\)", vsFindOptions.vsFindOptionsRegularExpression)) Then
            Return False
        End If
        order = order + 10
        sel.Text = "MemberOrder (" & order & ")"
        Return True
    End Function

End Module

Jun 29, 2012 at 4:04 PM

Thanks for posting that.  I did write a similar one a couple of years back when I was working on a project where the domain model was (required to be) in VB - but didn't share it as no one else seemed to be using VB.   (The macro was rather simpler for processing VB code, because properties have the word 'property' in them!).

Oct 16, 2012 at 12:08 PM

Sadly, macros are no longer supported in VS 2012.

Some time I'll have to try put this in a VS extension.

Oct 16, 2012 at 1:37 PM
As an alternative, you could write your own FacetFactory to, for example, parse a txt file that lists the order:



This would then install a MemberOrderFacet on each class member.

I'm not sure if the registering of FacetFactorys is public API, but it ought to be do-able. It is, at any rate, in the Apache Isis "sister" project on JVM, and the two projects share the same design in this regard.


On 16 October 2012 12:09, jfbosch <> wrote:

From: jfbosch

Sadly, macros are no longer supported in VS 2012.

Some time I'll have to try put this in a VS extension.

Read the full discussion online.

To add a post to this discussion, reply to this email (

To start a new discussion for this project, email

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at

Oct 16, 2012 at 1:43 PM
That would bring in a 3rd location to maintain an entity's properties.
Don't like so much, although I see the usefulness.