Share via


Design time expression editing 101

Here are the basic implementation details that you should know about the design time expression editing experience in the WF designer.

An expression is bound to an activity argument or property. In the designer, the expressions are displayed inside of an ExpressionTextBox control. You can enter one single expression per ExpressionTextBox. Statements are not supported. The lack of statement support means that if you need to declare variables, you must declare them in the Variable designer.

Inside of Visual Studio, there are two components you need to be aware of – the hostable editor and the hosted compiler. The hostable editor is a slimmed down version of the big VB IDE, complete with its own compiler. The hostable editor provides a full-fledged IDE experience, including IntelliSense, syntax highlighting, squiggles, pretty listing, parameter information, etc. It is totally separate and independent of the hosted compiler. It is also not available for use in a rehosted workflow designer.

The hosted compiler is used by the WF runtime to validate your expressions. The compiler is invoked by the validation service, and also in the background when you edit your expressions. When the hosted compiler determines that there is an error in your expression, there is a red error icon that shows next to the expression in the designer and the error message appears at the error list. The hosted compiler performs validation both at design time and at runtime.

The compiler inside the hostable editor is actually different from the hosted compiler. Both of these compilers are actually different than the regular VB compiler you find in the big VB IDE. (Why we have so many compilers is a story better not told.)  There are no interesting differences between the hostable editor and hosted compiler in terms of compilation features. However, there are some significant differences between the hostable editor/compiler and the big VB compiler that you should keep in mind, here they are:

  • Comments are not supported (sorry).
  • Snippets are not supported.
  • Statement lambdas are not supported.
  • You can’t use multi-dimensional array initialization syntax without explicitly stating the type. This means new Integer(,){{1,2},{3,4}} is valid syntax but {{1,2},{3,4}} is not. However, the type can be inferred for single dimensional arrays, so the syntax {1,2} is valid. (Note: WF designer support for multi-dimensional arrays will be discussed in another post).
  • My extensions have been turned off.
  • You can’t manipulate compiler options. Option strict has been turned on in the hosted compiler and can’t be turned off. Note: there are type coercion facilities built in. So if you have an Int16 variable named hello, you can assign hello=5. The compiler coerces the Int32 value 5 to an Int16 value for you. However, because Option strict is turned on the assignment statement hello=”hello” is invalid.

Comments