Using Expressions in Configuration Files |
Many attributes of the configuration schema accept expressions, which are dynamically evaluated. Expressions in the PostSharp configuration system work similarly as in XSLT. Substrings enclosed by curled brackets, for instance {$property}, are interpreted as XPath expressions.
For instance, the following code contains two XPath expressions:
<Project xmlns="http://schemas.postsharp.org/1.0/configuration"> <Property Name="LoggingEnabled" Value="{has-plugin('PostSharp.Patterns.Diagnostics')}" Deferred="true" /> <Multicast> <When Condition="{$LoggingEnabled}"> <d:Log /> </When> </Multicast> </Project>
Please check the MSDN documentation for general information about XPath.
![]() |
---|
In the context of PostSharp configuration files, XPath expressions cannot refer to XML elements or attributes, but only to variables, functions, operators and constants. |

PostSharp properties are mapped to XPath variables.
For instance, the expression {$LoggingEnabled} evaluates o the value of the LoggingEnabled property.

You can use any XPath function and operators.
Additionally to standard XPath 1.0 functions, PostSharp defines the following functions:
Function | Description |
---|---|
has-plugin(name) | Evaluates to true if the given plug-in is loaded, otherwise false. |
environment(variable) | Returns the value of an environment variable. |

An attribute value can contain both text and expressions. This is illustrated in the following example:
<Project xmlns="http://schemas.postsharp.org/1.0/configuration"> <Property Name="A" Value="A" /> <!-- Evaluates to A --> <Property Name="B" Value="B;{$A}" /> <!-- Evaluates to B;A --> <Property Name="C" Value="C;{$B};{$A}" /> <!-- Evaluates to C;B;A;A --> </Project>