Search code examples
visual-studioxamltfsbuild-process

What are square braces surrounding attribute values?


In the TFS DefaultTemplate.11.1.xaml build process template, there are many attributes whose entire values are surrounded by square braces [], so a tag has the form

<tagName attributeName="[attributeValue]">

where tagName, attributeName, and attributeValue are text strings.

I cannot find any documentation for this value syntax. From the template, it appears to cause the XAML processor to evaluate the text as an expression. Is this explained somewhere?


Solution

  • I believe that square braces in XAML do indeed denote a value expression. I am still uncertain exactly how this denotation is supported or enforced. Possibilities include:

    -XAML syntax; I think this is the most likely answer.

    -A Converter implementation somewhere which detects during parsing when a value begins and ends with square braces, and evaluates the content within during processing; I think this is the second-most likely answer.

    -It's possible that the square braces are actually not special characters and are valid as part of an identifier, the evaluation of the value is performed via some other as yet unknown mechanism, and the square braces are present by convention only, perhaps to indicate that the value is not a literal but an expression to be evaluated. I think this is an unlikely answer.

    Supporting research:

    "Expressions created in the WF designer are serialized using square brackets, which is shorthand for VisualBasicValue or VisualBasicReference"

    "Hand edit the workflow XAML file to change value of the Number property to [1+2] (the square brackets denote an expression)"

    "Expressions are literal values or Visual Basic code bound to arguments or properties. They contain value elements (e.g. variables, constants, literals, properties) that are combined with operations to yield a new value. Expressions are written using VB.NET syntax even if the application is in a program using C#."

    "Workflows produced by designer are saved in XAML, where expressions appear enclosed in square brackets."

    The last quote above is the only official documentation I have found that in any way mentions the square brace surrounding expressions as XAML attribute values, and this still does not clarify whether the designer does this merely arbitrarily and without invoking any special syntax, or if expressions must appear enclosed in square brackets according to the official XAML specification and as such the designer must do this.