Skip to content

Support Static Abstract Members in Interfaces #311

Description

@JasonBock

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions