Custom Aspect to make all public class methods and properties virtual using an aspect

avistokar's Avatar

avistokar

06 Nov, 2017 02:28 PM

Most mocking frameworks require a method to be defined in an interface or be virtual to be able to be mocked. For many classes that I build, the only reason to create an Interface would be for this purpose. This makes development brittle and/or cumbersome and I do not like to do it. It would be great if I could apply an aspect, (perhaps conditional on build config) that would allow me to make all public methods and properties virtual. Is this possible?

  1. Support Staff 1 Posted by PostSharp Techn... on 07 Nov, 2017 03:04 PM

    PostSharp Technologies's Avatar

    Hello,

    This kind of aspect can be created by implementing a custom weaver and using our low level SDK. Unfortunately we do not provide support for PostSharp SDK currently. There's a feature request on User Voice that you can vote on: https://postsharp.uservoice.com/forums/4949-feature-requests/sugges...

    Alternatively, it should be possible to implement a simple mocking framework using standard PostSharp Framework, MethodInterceptionAspect and several other aspects. This may require significant effort and probably you will not get all the features of the full framework. You can also suggest a mocking framework as another feature on the User Voice website.

    -alex

  2. Support Staff 2 Posted by PostSharp Techn... on 22 Nov, 2017 12:15 PM

    PostSharp Technologies's Avatar

    Hello,

    We are going to close this request as there have not been any further updates. Please feel free to reopen the discussion if you need more help.

    Thanks,
    PostSharp Team

  3. PostSharp Technologies closed this discussion on 22 Nov, 2017 12:15 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac