JasonBock / Rocks

A mocking library based on the Compiler APIs (Roslyn + Mocks)
MIT License
263 stars 20 forks source link

Resolve Event Extensions Issue With Open Generics #309

Open JasonBock opened 8 months ago

JasonBock commented 8 months ago

Open generics will be supported in 8.1.0 (issue #287) . However, there's a problem when the target type is generic, an open generic is requested, and the mock type has events. The extension methods generated need to be created in a static class that is also a top-level class, which is why these extension methods are generated in a separate class. However, with open generics, this presents a problem because the type parameters need to be specified, but there's no obvious way to do this.

Therefore, the extension methods are not generated in this scenario. Users can still use AddRaiseEvent(). However, it would be desirable to find a way to remove this limitation. It is possible that if the "extensions" feature was added in C#, it might make this possible, but there is no known delivery date of this feature (and it may never show up).