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

Fix InvalidOperationException when mocking class with overloaded property/indexer in base class #1155

Merged
merged 3 commits into from
Apr 9, 2021

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Apr 9, 2021

Fixes #1153.

@stakx stakx added this to the 4.16.2 milestone Apr 9, 2021
Comment on lines +365 to +373
var parameterTypes = new ParameterTypes(property.GetIndexParameters());
var derivedProperty = expression.Expression.Type
.GetMember(property.Name, MemberTypes.Property, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Cast<PropertyInfo>()
.SingleOrDefault(p => p.PropertyType == property.PropertyType);
.SingleOrDefault(p =>
{
return p.PropertyType == property.PropertyType
&& new ParameterTypes(p.GetIndexParameters()).CompareTo(parameterTypes, true, false);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could possibly be optimized further. Ideally, we'd avoid the calls to .GetIndexParameters(), as well as the comparison, by checking first whether both PropertyInfos are of the same type (property vs. indexer), and only doing the comparison when both are indexers.

@stakx stakx merged commit a6fde8b into devlooped:main Apr 9, 2021
@stakx stakx deleted the indexers branch April 9, 2021 20:42
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.

Issue mocking Vb.Net class with overloaded property in base class
1 participant