0

Background

I'm building an automation framework (just a bunch of C# classes/interfaces) to drive a desktop application using Appium and WinAppDriver. One of the awesome features offered by Appium/WinAppDriver is the ability to take a screenshot of the running application at any time. I want to easily toggle on/off screenshot capture upon every method call of my automation framework without altering every method of my automation framework because that is effort and a lot of code duplication and also pretty boring.

Ideal solution

I'd like to use the magic that is reflection (or a third party library if one exists) to write a piece of code that says before executing any method on this object, execute this other piece of code. Is this even possible?

Sara Gowen
  • 57
  • 4
  • While you can [replace a method](https://stackoverflow.com/questions/7299097/dynamically-replace-the-contents-of-a-c-sharp-method), it might be better to see if you can automatically create a proxy object, in the way that `ImpromptuInterface` does, for example. – ProgrammingLlama Nov 23 '21 at 13:33
  • Anything is possible with aspect-oriented programming. – Ian Kemp Nov 23 '21 at 13:41
  • You can probably do that with [Fody](https://github.com/Fody/Fody) or source generators if the APIs you are using support .NET 5. Though I'm not sure either would be better than altering your design to support it. – Crowcoder Nov 23 '21 at 13:43
  • Omigosh, the Harmony library is amazing and absolutely does what I want it to! https://github.com/pardeike/Harmony Thanks everyone for pointing me to the other stack overflow question/answer – Sara Gowen Nov 23 '21 at 15:52

0 Answers0