ExpressionPropertyEditor. Getting Started

This topic explains, how to implement the ExpressionObject business class, which allows to demonstrate the functionality of the Xafari expressions designer. Follow the steps described below.

  • Open the existing XAF solution or create a new one.
  • Add XafariModule and XafariEditorsModule to the Module Project.
  • Add XafariWinModule and XafariEditorsWinModule to the Windows Forms Application Project.
  • Add XafariWebModule and XafariEditorsWebModule to the Web Application Project.
  • Add a new Domain Component to the Module Project; name it ExpressionObject, declare the Expression and Type properties as shown in the code below:
  • c#
  • VB

//...
[EditorAlias("ExpressionPropertyEditor")]
[CriteriaOptions("Type")]
string Expression { get; set; }
[ImmediatePostData]
[ValueConverter(typeof(TypeToStringConverter))]
Type Type { get; set; }
//...

'...
<EditorAlias("ExpressionPropertyEditor")> _
<CriteriaOptions("Type")> _
Friend Property Expression As String
<ImmediatePostData> _
<ValueConverter(GetType(TypeToStringConverter))> _
Friend Property Type As Type
'...

The EditorAlias attribute indicates, that the Expression property will be displayed via the ExpressionPropertyEditor. An alternative approach is to use the Model Editor.

As expressions are quite often created in the context of a business object, the possibility to associate the expression with the respective type is required.

To bind the expression to the context type, the Type property is declared, and the [CriteriaOptions("Type")] attribute is set for the Expression property. It means that the Type property specifies the context type for the expression. If the context type is null, then the expression editor does not display the property tree.

  • Run the application and navigate to the ExpressionObject_DetailView. The ExpressionPropertyEditor functionality described in the Runtime capabilities topic.

You can see the code used in this topic in the ExpressionObject.cs  file of the Feature Center demo installed with Xafari.

Note:

To calculate the value of the expression it is necessary to use the GetValue method of the ExpressionCalculator static class: ExpressionCalculator.GetValue(expression, context, parameters);