We are in the progress of introducing PostSharp in one of our projects. It's been working great so far! There is one thing though that we haven't managed to solve: how to fire an advice conditionally.
Details: - we have an attribute StopWatchAttribute which makes it possible to record the time needed to run methods - this attribute accepts an enumeration "LoggingLevel" which is set in the config file with values like 0, 1, 2 etc - this parameter is read in a base class called BaseService during runtime: new BaseService().CurrentLoggingSettings - we tried to set up the attribute constructor like StopWatchAttribute(new BaseService().CurrentLoggingLevel) but we get a compile error: an attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type.
--> summary: we would like the advice to be called conditionally and the condition depends on the parameter in the constructor of the attribute.
Is this possible to do?
Thanks for your help, Andras