I am implementing an aspectual PostSharp library and cannot find a solution to the following problem.
Suppose we have an aspect that will apply to some methods and will not apply to others. I need some mechanism that I can use at run time to find out if an aspect has been applied to the method. In particular, what is the recommended way to determine at runtime whether a specific aspect has been applied to a specific method given System.Reflection.MethodBase?
The first solution that comes to my mind is to make PostSharp mark every method that has been modified by this aspect with a custom attribute and use it methodBase.CustomAttributesat runtime. Is this the correct solution to the problem? Or perhaps PostSharp already has a ready-to-use or more elegant solution.
Also note that a solution that does not require a paid PostSharp license is preferable, since Free Community Edition is enough for my current project. In any case, it would be very interesting to discuss solutions based on the paid features of PostSharp.
source
share