-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Support basic cases in UseRangeOperator #45693
Support basic cases in UseRangeOperator #45693
Conversation
return false; | ||
} | ||
|
||
if (_methodToMemberInfo.TryGetValue(method, out memberInfo)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (_methodToMemberInfo.TryGetValue(method, out memberInfo)) | |
if (!_methodToMemberInfo.TryGetValue(method, out memberInfo)) |
then have hte logic to try to produce the value in the if-statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
/// <summary> | ||
/// Can be null, if we are dealing with one-argument call to a slice-like method. | ||
/// </summary> | ||
public readonly IOperation Op2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public readonly IOperation Op2; | |
public readonly IOperation? Op2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
var targetMethod = invocation.TargetMethod; | ||
|
||
// Try to see if we're calling into some sort of Slice method with a matching | ||
// indexer or overload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not finding tehse comments helpful. having real world examples of the before/after would be more helpful here imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I re-worded the comment.
targetMethod, | ||
memberInfo, | ||
startOperation, | ||
null); // secondOperation is null: the range will run to the end. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
named param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
null); // secondOperation is null: the range will run to the end. | ||
} | ||
|
||
private static Result? AnalyzeInvocationWithTwoArguments( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static Result? AnalyzeInvocationWithTwoArguments( | |
private static Result? AnalyzeTwoArgumentInvocation( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also renamed AnalyzeInvocationWithOneArgument
to AnalyzeOneArgumentInvocation
.
// From: https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/ranges.md#decisions-made-during-implementation | ||
// | ||
// When looking for the pattern members, we look for original definitions, not | ||
// constructed members |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just make this a normal method. breaking up an expression with complex comments like this just makes things too hard to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
// of the range. i.e. `start..` | ||
if (IsInstanceLengthCheck(lengthLikeProperty, instance, endOperation)) | ||
var endFromEnd = false; | ||
ExpressionSyntax endExpr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just make this null, and then just set it in the case where we have it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
var overloadWithTwoArguments = method.ContainingType | ||
.GetMembers(method.Name) | ||
.OfType<IMethodSymbol>() | ||
.FirstOrDefault(s => IsSliceLikeMethod(s)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we rename IsSliceLikeMethod to IsTwoArgumentSliceLikeMethod?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed; also renamed IsSliceLikeMethodWithOneArgument
to IsOneArgumentSliceLikeMethod
.
Nice start! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Thanks much!
Feel free to ping me when this passes, and i'll merge in. Thanks! |
@CyrusNajmabadi thanks for the feedback! It’s ready for merging now. |
Thank you for the contribution! |
@mahalex Nice! |
Fixes #45637