This is the online documentation for PostSharp 5.0.
Download PDF or CHM. Go to v4.3 or v5.0

Accessing Configuration from Source Code

Even if most configuration settings are consumed by PostSharp or its add-in, it is sometimes useful to access configuration elements from user code. The PostSharp.dll library gives access to both configuration properties and extension configuration elements.

This topic contains the following sections:

Accessing properties

You can read the value of any PostSharp property by including it in an XPath expression and evaluating it using the EvaluateExpression(String) method of PostSharpEnvironment.CurrentProject:

string value = PostSharpEnvironment.CurrentProject.EvaluateExpression("{$PropertyName}")

For details regarding expressions, see Using Expressions in Configuration Files.

Accessing custom sections

You can get a list of custom sections of a given name and namespace by calling the GetExtensionElements(String, String) method of PostSharpEnvironment.CurrentProject:

IEnumerable<ProjectExtensionElement> elements = 
     PostSharpEnvironment.CurrentProject.GetExtensionElements( "MyElement", "uri:MyNamespace" );

Extension elements must be declared using the SectionType element.

See Also