提交 9f3e4ada 编写于 作者: C Cyrus Najmabadi

support implicit indexing pattern

上级 5badf86b
......@@ -471,6 +471,32 @@ void Goo(string[] s)
{
var v1 = s[^2][^1];
}
}", parseOptions: s_parseOptions);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseIndexOperator)]
public async Task TestSimple_NoIndexIndexer_SupportsIntIndexer()
{
await TestAsync(
@"
using System.Collections.Generic;
namespace System { public struct Index { } }
class C
{
void Goo(List<int> s)
{
var v = s[[||]s.Count - 1];
}
}",
@"
using System.Collections.Generic;
namespace System { public struct Index { } }
class C
{
void Goo(List<int> s)
{
var v = s[^1];
}
}", parseOptions: s_parseOptions);
}
}
......
......@@ -83,15 +83,14 @@ private MemberInfo ComputeMemberInfo(IMethodSymbol method, bool requireIndexMemb
if (method.MethodKind == MethodKind.PropertyGet)
{
// this is the getter for an indexer. i.e. the user is calling something
// like s[...]. We need to see if there's an indexer that takes a System.Index
// value.
var indexer = GetIndexer(containingType, IndexType, method.ReturnType);
if (indexer != null)
{
// Type had a matching indexer. We can convert calls to the int-indexer to
// calls to this System.Index-indexer.
return new MemberInfo(lengthLikeProperty, overloadedMethodOpt: null);
}
// like s[...].
//
// These can always be converted to use a System.Index. Either because the
// type itself has a System.Index-based indexer, or because the language just
// allows types to implicitly seem like they support this through:
//
// https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/ranges.md#implicit-index-support
return new MemberInfo(lengthLikeProperty, overloadedMethodOpt: null);
}
else
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册