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

Make MethodCall classes non-generic #663

Merged
merged 8 commits into from
Aug 25, 2018

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Aug 25, 2018

This is achieved by separating the fluent API (which relies heavily on the type system and generics) from the actual implementation code. Fluent API methods are moved into generic types in the Moq.Language.Flow namespace. These new types wrap MethodCalls and implement the fluent API interfaces. MethodCall et al. then no longer need to implement those, nor need they be generic anymore.

Getting rid of generics in the MethodCall types should allow us to apply optimizations, de-duplications and code simplifications much more easily because static types won't get in the way needlessly everywhere.

This benefit can be seen already by the removal of two redundant MethodCall types: MethodCall<T> and SetterMethodCall<T, TProperty>, both of which were essentially duplicates of MethodCall.

@stakx stakx added this to the 4.9.1 milestone Aug 25, 2018
Remove the fluent API interface implementations from `MethodCall` et
al., and create new dedicated API types that implement them instead.
To start off, these new types simply forward all calls to the `Method-
Call` instances that they wrap.

This might initially seem pointless, but it means that `MethodCall` et
al. are no longer forced to implement lots of duplicate methods and be
generic just because the fluent API requires it. We'll be able to trim
down `MethodCall` et al., possibly even combine them into a single
non-generic `MethodCall` type, then translate that simpler API into a
generic, type-safe API in the newly added types.
Instead of forwarding the API types' various `Callback` methods to the
corresponding `Callback` methods, which delegate to `SetCallbackWith-
Arguments` and `SetCallbackWithoutArguments`, combine the latter into
a new uniform method `SetCallbackResponse` and let the API types call
that one directly.
This subclass of `MethodCall` was previously only needed for its
specially typed `Callback` method. This method was part of the fluent
API, which has now been separated into new dedicated types.
Instead of forwarding the API types' various `Raises` methods to the
corresponding `Raises` methods, which delegate to `RaisesImpl`, rename
the latter to `SetRaiseEventResponse` and delegate to those directly.
This class has become practically identical with its base class
`MethodCall` when its fluent API `Raises` methods were removed. Use
the non-generic base class directly.
@stakx stakx merged commit 83df927 into devlooped:master Aug 25, 2018
@stakx stakx deleted the non-generic-methodcall branch August 25, 2018 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant