4

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?

qujck
  • 14,388
  • 4
  • 45
  • 74

2 Answers2

6

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.

Gael Fraiteur
  • 6,759
  • 2
  • 24
  • 31
  • 1
    Another thing that came onto my mind is adding a method throwing an exception and annotate it with an around aspect that replaces this method entirely. One advantage is that you won't have to add a reference to PostSharp for this assembly and keep your aspects anywhere else. `[NoopAspect] pubic void EnsureWeaving() { throw new Exception("Weaving was skipped"); }` The `NoopAspectAttribute` implementation would then not call `args.Proceed()` and the exception is then not thrown when PostSharp is enabled. – Peit Nov 25 '12 at 13:45
0

On one hand you will see it in the output window during or after the build (sth. like : message : PostSharp complete -- 0 errors, 0 warnings, served in 1073 ms) on the other hand you could inspect your assemblies with .net reflector or similar tools (JetBrains dotPeek is free) hence postsharp is weaving your aspects in the IL code during the build process.

There might be more options like inspecting the .pdb-files, too. Will this be enough for your needs?

Peit
  • 882
  • 6
  • 17
  • I guess no option would be foolproof but I would like to remove the human factor by implementing some sort of runtime check. – qujck Nov 23 '12 at 10:22