Skip to content

Member Format Expressions

Simon Mourier edited this page Feb 19, 2020 · 1 revision

Using CodeModeler, you can use “Member Format Expressions” to customize the way names of entities and properties are displayed in the design surface. The access is in the “Modeler Pad” ribbon tab:

Member Format Expressions - Picture 70

Several expressions are provided by default, but you can also define your own expressions by selecting “Choose” (you do this from the “Modeler Tab” of the ribbon or from the contextual menu):

Member Format Expressions - Picture 71

Clicking “Add New” will allow you to define your own:

Member Format Expressions - Picture 72

Here we define an expression displaying the property name and indicating if the property is a key between parenthesis. Here is the result on entity shapes:

Member Format Expressions - Picture 73

If you prefix your property path with a ‘#’, the value will be “decamelized” as shown in the image. For instance, the expression {Name} (IsKey={IsKey}) will display this (the difference is visible on the Line1 and Line2 properties):

Member Format Expressions - Picture 74

Tags

Member Format Expression also supports “tags” (as in HTML). Three tags are supported in expressions:

  • Font: use it to define styles in your expression,

  • If: use it to define conditions,

  • Else: same as if.

For instance, specifying the following expression <font color="blue">{#Name}</font> will display the entity shape like this:

Tags - Picture 75

But we can use the If tag like this <if condition=IsKey><font color="red">{#Name}</font><else/><font color="#00FFFF">{#Name}</font></if>  and this is how the shape will be displayed:

Tags - Picture 77

To ensure expressions don’t get too long the Font tag also has a condition attribute so you don’t necessarily have to wrap it in an If tag. Therefore, you could get the same result using this expression <font condition=IsKey color="red">{#Name}<else/><font color="#00FFFF">{#Name}</font></font>.

The Font tag supports the following attributes:

  • family: takes a font family name (e.g. Lucida Console),

  • size: a font size in pt,

  • stretch: a font stretch (System.Windows.FontStretch),

  • style: a font style (System.Windows.FontStyle),

  • weight: a font weight (System.Windows.FontWeight),

  • color: a color (can take a value from System.Windows.Media.Brushes, or a #RGB value, or a #ARGB),

  • decorations: a comma separated list of System.Windows.TextDecorations,

  • trimming: a text trimming (System.Windows.TextTrimming),

  • alignment: a text alignment (System.Windows.TextAlignment),

  • direction: a flow direction (System.Windows.FlowDirection),

  • lineheight: a line height,

  • maxwidth: a maximum text width,

  • maxheight: a maximum text height,

  • maxlinecount: a maximum line count,

  • condition: a condition to be evaluated.

The condition attribute supports the following operators:

  • == or = for a case-insensitive equals,

  • [=CS] for a case-sensitive equals,

  • !=, \<\> for a case insensitive not equals,

  • [!=CS] for a case sensitive not equals,

  • \>= for greater than equals,

  • \<= for lower than equals,

  • \> for greater than,

  • \< for lower than,

  • [StartsWith] for a case-insensitive starts with,

  • [StartsWithCS] for a case-sensitive starts with,

  • [EndsWith] for a case-insensitive ends with,

  • [EndsWithCS] for a case-sensitive ends with,

  • [Contains] for a case-insensitive contains,

  • [ContainsCS] for a case-sensitive contains.

For example, here’s how to highlight all properties ending with “Id”: <font condition="Name [EndsWith] 'Id'" color='red'>{#Name}<else/>{#Name}</font>

Note: don’t forget to surround the right-side statement with quotes so the evaluator knows it’s a string.

There are also shortcuts such as you don’t have to specify > 0 for numbers, for instance this expression {#Name}<font condition='AllRules.Count' color='#007F0E'> (Rules={AllRules.Count})</font> will suffix properties with (Rules=X) in green::

Tags - Picture 78

Note: Use member format expressions with caution as they’ll be evaluated for all property names, so the lighter they are, the better rendering performances will be and vice versa.

The MessagesBrowser Class

The MessagesBrowser class is a dynamic class you can use as a property path in Member Format Expressions which allows you to access messages (resources) defined for the current concept (entity or property).

For instance, if you defined English resources for each of your address properties in the documentation (“_doc”) class, like this:

The MessagesBrowser Class - Picture 55

Using this expression {#Name} ({MessagesBrowser._doc.en-US}), you can use them directly in the property line like this:

The MessagesBrowser Class - Picture 76

Note: For performance results the* MessagesBrowser *class is cached and built on first access, so that defining a new resource or editing one will not be reflected immediately on the surface.

Advanced Sample

Thanks to the extensibility of the CodeModeler, you can customize your working environment to fit your need. With the property member format, you can visualize lots of information about your model very quickly.

Let’s suppose you have defined this entity in your model:

Advanced Sample - Picture 79

Then, using this Member Format Expression:

<if condition=IsEntityDisplay>-> </if> <if condition=IsNullable>({Name})<else />{Name}</if> : {DisplayTypeName} <if condition="'true'=Element.GetAttribute('localizable','http://www.softfluent.com/cm/aspects/localization/2018/1')">(Localizable)</if> <if condition=Relations.Count>({CascadeDelete})</if>

Entity shapes will look like this:

Advanced Sample - Picture 80

  1. The icon indicates the property is a member of the primary key

  2. Parentheses indicate the property is nullable

  3. "(Localizable)" indicates the property is localizable when using the Localization aspect

  4. "->" indicates the property is the “entity display name” property

  5. The icon indicates the property type is an enumeration

  6. "(None)", "(Before)" or "(After)" indicates the selected Cascade Delete option of the relation

  7. "*" the infinite symbol indicate the property type is a collection

Clone this wiki locally