Closed jtschuster closed 2 years ago
Sorry for the force push, I ran into issues with rebasing and it seemed like the cleanest option. I've updated the description to describe the updated code. This version differentiates SourceParameterIndex and this
parameters to ensure the SourceParameterIndex will always be able to index MethodReference.Parameters
I've run into multiple issues when I think an
int parameterIndex
is the source-based index when it is the IL-based index (offset by 1 forthis
) or vice versa.In order to fix this, we can use different enums for each definition of "Parameter Index" to enforce the correct usage and avoid the off by one errors. The enums rely on the underlying
int
value to provide the index number.This change adds
ILParameterIndex
to represent the IL-based indexing where 0 may refer tothis, and SourceParameterIndex where 0 is the first "real" parameter in C# source code. Converting from ILParameterIndex to SourceParameterIndex returns a SourceParameterKind to differentiate between
thisand other parameters and ensure that any
SourceParameterIndexwill be able to index
MethodReference.Parameters`.It uses these in
ParameterReferenceValue
as well asGetMethodParameterValue()
and adds aGetMethodThisParameterValue()
,ThisParameterReferenceValue
, and bubbles the changes where necessary.Most places should use SourceParameterIndex, and convert to ILParameterIndex when necessary or at the boundary of updated and old code.
I'll continue to update the code to use these enums in other PRs.