Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Static Abstract Members in Interfaces #311

Open
JasonBock opened this issue Apr 22, 2024 · 1 comment
Open

Support Static Abstract Members in Interfaces #311

JasonBock opened this issue Apr 22, 2024 · 1 comment

Comments

@JasonBock
Copy link
Owner

JasonBock commented Apr 22, 2024

Describe the solution you'd like
This was something I thought I looked at before, but for some reason I can't find any notes. Anyway...

C# 11 added static abstract members in interfaces, or SAMIs. Part of the reason I didn't try to support it originally is that the attributes were generic, and you can't pass interfaces to type parameters that contain SAMIs. However, with the open generics feature implemented, I now have attributes that expect a Type to be passed in (typically with typeof(...)). That means I could add support for SAMIs, but there are a number of things to consider:

  • The mock type has to be public when SAMIs exist. This....shouldn't be problematic, but need to ensure that there are no name duplications. I may be able to narrow this down somewhat if we have SAMIs that are not operators, then the type will be made public (or maybe just internal). Rationale here is that if you're implementing an interface with just operators (like IAdditionOperators<,,> - https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Numerics/IAdditionOperators.cs,67cc175feb3d46df), I don't think there's a need to expose the mock type in that case.
  • If tests are run in parallel, some kind of mechanism needs to be put in place to ensure expectations on a static member work as expected. Using AsyncLocal<> may help here, though I need to do a POC outside of Rocks in testing frameworks to see if this would work.
  • Related to the previous point, I may need to make expectations disposable. The reason why is that I may need a context to clear out any underlying mechanism with expectations on static members, and having a Dispose() method may do the trick.
  • I may need to add an Operators "section" to the gen-d code, similar to what I do with Methods, Properties, and Indexers.

Describe alternatives you've considered
Leave things as-is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant