PostSharpDeployment and ConfigurationConfigurationAccessing Configuration from Source Code
Open sandboxFocusImprove this doc

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.

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 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 CurrentProject:

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

Extension elements must be declared using the sectiontype element.

See Also

Other Resources

Using Expressions in Configuration Files
Configuring Projects Using postsharp.config