Expressions in MindFusion.Reporting are conceptually very similar to expressions in various programming languages, such as C# and Visual Basic. An expression is a text fragment that can be evaluated to a single value or object. Expressions can contain a literal value, a function invocation, an operator and its operands, or a field name.
Expressions can use operators that in turn use other expressions as parameters, or function calls whose parameters are in turn other method calls, so expressions can range from simple to very complex.
The simplest type of expression is a literal. A literal is a constant value written directly in the expression. For example 5 and "Hello World" in the example below are both literals.
Expression Copy Code |
---|
"Hello World" |
The first line in the example is an expression containing a single literal - the string "Hello World". The second line is another expression containing the number 5. Both of these expressions evaluate to their contained literals.
Literals in MindFusion.Reporting can be numbers, strings and colors. The string literals should be enclosed in quotes. The color literals have the format #RRGGBB, where RR, GG and BB are the hexidecimal representations of the red, green and blue channels of the color.
You can include names of table fields in an expression. The available fields to choose from depend on the context in which the expression is evaluated. For example, if you include an expression in a Label's text, the fields that can be referenced within the expression are only those contained in the data table bound to the DataRange object, containing the label. If the label is not contained in a data range, or the data range is not data-bound, no fields will be available for use in the expression.
The following example shows an expression, which concatenates two data fields of type string - FirstName and LastName:
Expression Copy Code |
---|
FirstName + " " + LastName |
For more information on how to use expressions, check Using Expressions in Reports.
Report parameters can be referenced in expressions by using the "Parameters." or "Report." keywords followed by the name of the parameter. For example, the expresion below references a parameter named MyParam:
Expression Copy Code |
---|
Parameters.MyParam |
For more information about report parameters and how to use them in expressions, check Report Parameters.
The following example demonstrates another type of expression, called function invocation. The function in the example is Len with a single string argument.
Expression Copy Code |
---|
Len("Hello World") |
A function invocation requires the name of the function, followed by parenthesis and any function parameters. The function invocation evaluates to the return value of the function. In the above example, the invocation will evaluate to the number of characters in the string specified as argument, that is, 11.
Each function expects arguments of specific type. Passing an argument of type that does not match the type the function expects will either result in false evaluation or a run-time error. Additionally, the number of arguments passed to the function should match the number of arguments expected.
There are numerous predefined functions that can be called within an expression. A complete list with all available functions, see Function Reference.
An operator is a symbol that takes one or more expressions, called operands, as input and returns a value. Operators that take one operand, such as the unary minus operator (-) are called unary operators. Operators that take two operands, such as arithmetic operators (+, -, *, /) are called binary operators. In MindFusion.Reporting there are no tertiary operators.
The following example illustrates an expression that is the sum of two numbers (operands).
Expression Copy Code |
---|
2 + 3 |
The operand of an operator can be any valid expression that evaluates to a value of the same type as the one expected by the operator. For example, the following expression applies operators to the result of a function invocation, then passes the result as an argument to another function.
Expression Copy Code |
---|
Sqrt(Pow(SideA, 2) + Pow(SideB, 2)) |
The example evaluates the hypotenuse of a right triangle with sides identified by the fields SideA and SideB respectively.
The following table describes the operators available in MindFusion.Reporting in more details:
Operator | Description |
---|---|
+ | Addition. The addition operator can work on both number and string operands, including mixing between both. |
- | Subtraction or Unary minus. Can be applied on numeric operands. |
! | Logical negation. Unary operator that can be applied only on boolean operands. |
*, / | Multiplication and Division. Can be applied to any numeric operands. |
% | Modulo. Can be applied on integer operands and returns the reminder of the division between them. |
<, >, <=, >= | Comparison operators. Can be used on numeric operands. |
==, <> | Equality operators. Can be used on numeric and string operands. |
&&, || | Logical AND and OR operators. Can be applied on boolean operands. |
&, ^, | | Bitwise operators (OR, XOR and OR). Can be applied on integer operands. |
The operators encountered in an expression are evaluated according to their precedence. Operators with higher priority are evaluated before operators with lower priority. For example, the following example will evaluate to 14, because the multiplication will be evaluated first.
Expression Copy Code |
---|
2 + 3 * 4 |
You can change operator precedence by using parenthesis. Changing the order of the operators in the above example, so that the addition is evaluated first, can be done like this:
Expression Copy Code |
---|
(2 + 3) * 4 |
The following table lists the operators in order of precedence:
Unary | - (unary), ! |
Arithmetic - Multiplicative | *, /, % |
Arithmetic - Additive | +, - (binary) |
Relational | <, >, <=, >= |
Equality | ==, <> |
Logical, in order of precedence | &, ^, | |
Conditional, in order of precedence | &&, || |