Search code examples
c#aoppostsharp

How to guarantee postsharp code has been injected?


This is a hypothetical question regarding the use of PostSharp.

I presume that if the PostSharp portion of the build were to be missed for any reason the attributes would be ignored and the built assemblies could still run. If I implemented security with aspects this would be a big problem.

How can I confirm at runtime that the PostSharp stage of the build happened and that my aspects are in the assemblies?


Solution

  • You can evaluate PostSharp.Post.IsTransformed at runtime. If the assembly has been transformed, the call to this property is changed to just the constant true. Since the property itself always returns false, you can know whether the assembly that calls PostSharp.Post.IsTransformed has been transformed.