File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Microsoft.Toolkit.HighPerformance/Enumerables Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,16 @@ public bool MoveNext()
76
76
{
77
77
this . start = newEnd ;
78
78
79
- int index = this . span . Slice ( newEnd ) . IndexOf ( this . separator ) ;
79
+ // We need to call this extension explicitly or the extension method resolution rules for the C# compiler
80
+ // will end up picking Microsoft.Toolkit.HighPerformance.ReadOnlySpanExtensions.IndexOf instead, even
81
+ // though the latter takes the parameter via a readonly reference. This is because the "in" modifier is
82
+ // implicit, which makes the signature compatible, and because extension methods are matched in such a
83
+ // way that methods "closest" to where they're used are preferred. Since this type shares the same root
84
+ // namespace, this makes that extension a better match, so that it overrides the MemoryExtensions one.
85
+ // This is not a problem for consumers of this package, as their code would be outside of the
86
+ // Microsoft.Toolkit.HighPerformance namespace, so both extensions would be "equally distant", so that
87
+ // when they're both in scope it will be possible to choose which one to use by adding an explicit "in".
88
+ int index = System . MemoryExtensions . IndexOf ( this . span . Slice ( newEnd ) , this . separator ) ;
80
89
81
90
// Extract the current subsequence
82
91
if ( index >= 0 )
You can’t perform that action at this time.
0 commit comments