How to guarantee that postsharp code has been entered?

This is a hypothetical question about using PostSharp.

I assume that if part of the PostSharp assembly was missing for some reason, the attributes will be ignored, and inline assemblies can still be executed. If I implemented security with aspects, that would be a big problem.

How can I confirm at runtime that the PostSharp build phase has occurred and that my aspects are in assemblies?

+4
source share
2 answers

You can evaluate PostSharp.Post.IsTransformed at runtime. If the assembly was converted, the call for this property changes only to the constant true . Since the property itself always returns false , you can find out if the assembly that invokes PostSharp.Post.IsTransformed .

+6
source

On the one hand, you will see it in the output window during or after assembly (for example : message : PostSharp complete -- 0 errors, 0 warnings, served in 1073 ms ), on the other hand, you could check your assemblies using a reflector .net or similar tools (JetBrains dotPeek is free), therefore postsharp weaves your aspects in IL code during the build process.

There may be more options, such as checking .pdb files. Will it be enough for your needs?

0
source

Source: https://habr.com/ru/post/1447907/


All Articles