MindFusion.Reporting for Silverlight Programmer's Guide
Overview

Expressions in MindFusion.Reporting for Silverlight 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 member reference.

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.

Literals

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"
5

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 for Silverlight 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 hexadecimal representations of the red, green and blue channels of the color.

Identifiers

Identifiers are character sequences starting with a letter and containing an arbitrary number of letters and numbers. The following expressions are examples of identifiers:

Expression  Copy Code

Price
width
label1

An identifier can be evaluated to either a member in the current data context or an object in the report. For example, if identifier expression is associated with a label contained in a DataRange, bound to a table data source, then the identifier will be interpreted as a field in that table. The special identifier this evaluates to the object containing the expression - usually a label.

The following example shows an expression,which concatenates two data fields of type string - FirstName and LastName:

Expression  Copy Code

FirstName + " " + LastName

In the case when the identifier evaluates to an object, the dot (.) operator can be applied to it in order to reference a member of this object. The following expression will evaluate to the width of the object containing the expression:

Expression  Copy Code

this.Width

For more information on how to use expressions in labels check Using Expressions in Label Texts.

Invoking Functions

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.

Operators

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 for Silverlight 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 specified by the identifiers SideA and SideB respectively.

The following table describes the operators available in MindFusion.Reporting for Silverlight 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.

.

Member reference operator. Can be applied to objects in order to reference a member.

Operator precedence

The operators encountered in an expression are evaluated according to their precedence. Operators with higher priority are evaluated before operators with lower priority. 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 performed first, can be done like this:

Expression  Copy Code

(2 + 3) * 4

The following table lists the operators in order of precedence:

Member reference

.

Unary

- (unary), !

Arithmetic - Multiplicative

+, - (binary)

Arithmetic - Additive

<, >, <=, >=

Relational

<, >, <=, >=

Equality

==, <>

Logical, in order of precedence

&, ^, |

Conditional, in order of precedence

&&, ||