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

Simplify code in Match.Matches and It.IsAny<T> #911

Merged
merged 6 commits into from
Aug 29, 2019

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Aug 29, 2019

I've long been bothered by the convoluted conditions inside It.IsAny<T> and Matcher.Matches (which gets executed just before the former). These can be simplified & easier to understand.

@stakx stakx added this to the 4.13.0 milestone Aug 29, 2019
by documenting that `IsAssignableFrom` generally yields the same
results as the `is` operator when run on an `object`-typed variable.

Note that this is removing the `IsComObject` check as well. This check
was originally added because it was found that `IsAssignableFrom` does
not always work properly for COM interfaces whereas the `is` works.
Since we're generally going back on `is`, the COM check becomes redun-
dant.
@stakx stakx merged commit bf97c56 into devlooped:master Aug 29, 2019
@stakx stakx deleted the simplify-matchers branch August 29, 2019 21:23
ishimko pushed a commit to ishimko/moq4 that referenced this pull request Sep 2, 2019
In `Match.Matches`:

* Split up `if` conditions so only null checks remain at top level
* Turn second `if` into `else`
* Instead of `return`ing early, set `canCastValueToT` bool to `false`
* Rename variable `matchType` -> `t` for clarity
* Remove redundant `is` check in `It`
  ... because `Match` matchers will already have checked `value is T`
  by the time the predicate delegate gets invoked.

In `It.IsAny<T>`, `It.IsNotNull<T>`:

* Simplify `It.IsAny<T>`, `It.IsNotNull<T>` matchers
  by documenting that `IsAssignableFrom` generally yields the same
  results as the `is` operator when run on an `object`-typed variable.

  Note that this is removing the `IsComObject` check as well. This
  check was originally added because it was found that `IsAssignable-
  From` does not always work properly when RCW `__ComObject` gets in-
  volved, whereas still `is` works even in that case. Since we're
  generally going back on `is`, the COM check becomes redundant.
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