I'm implementing a PostSharp aspect library and can't find out a solution to the following problem.
Suppose we have an aspect that will be applied for some methods and won't be applied for the others. I need some mechanism that I can use at runtime to know whether an aspect was applied to a method. Specifically, what is the recommended way to determine at runtime whether certain aspect was applied to a particular method given by a System.Reflection.MethodBase
?
The first solution that comes into my head is to make PostSharp mark every method that has been modified by this aspect with a custom atribute and use methodBase.CustomAttributes
at runtime. Is this the right solution for the problem? Or maybe there already is a ready-to-use or more elegant solution in PostSharp.
Also, please take into account that preferred is a solution that doesn't require a paid PostSharp license since Free Community Edition is enough for my current project. Anyway, it would be very intresting to discuss solutions based on paid PostSharp functionality too.