未验证 提交 001a62df 编写于 作者: J Julien Couvreur 提交者: GitHub

Honor type style preferences on tuple literals (#23936)

上级 6dc35229
......@@ -1573,8 +1573,19 @@ public async Task SuggestVarOnLocalWithIntrinsicTypeTuple()
var after = @"class C { static void M() { var s = (a: 1, ""hello""); } }";
await TestInRegularAndScriptAsync(before, after, options: ImplicitTypeEverywhere());
await TestInRegularAndScriptAsync(before, after, options: ImplicitTypeWhereApparentAndForIntrinsics());
await TestMissingInRegularAndScriptAsync(before, new TestParameters(options: ImplicitTypeWhereApparent()));
}
// We would rather this refactoring also worked. See https://github.com/dotnet/roslyn/issues/11094
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUseImplicitType)]
[WorkItem(11094, "https://github.com/dotnet/roslyn/issues/11094")]
public async Task SuggestVarOnLocalWithNonApparentTupleType()
{
var before = @"class C { static void M(C c) { [|(int a, C b)|] s = (a: 1, b: c); } }";
var after = @"class C { static void M(C c) { var s = (a: 1, b: c); } }";
await TestInRegularAndScriptAsync(before, after, options: ImplicitTypeEverywhere());
await TestMissingInRegularAndScriptAsync(before, new TestParameters(options: ImplicitTypeWhereApparentAndForIntrinsics()));
await TestMissingInRegularAndScriptAsync(before, new TestParameters(options: ImplicitTypeWhereApparent()));
}
......
......@@ -75,6 +75,21 @@ internal static class TypeStyleHelper
CancellationToken cancellationToken,
ITypeSymbol typeInDeclaration = null)
{
// tuple literals
if (initializerExpression.IsKind(SyntaxKind.TupleExpression))
{
var tuple = (TupleExpressionSyntax)initializerExpression;
foreach (var argument in tuple.Arguments)
{
if (!IsTypeApparentInAssignmentExpression(stylePreferences, argument.Expression, semanticModel, cancellationToken, typeInDeclaration))
{
return false;
}
}
return true;
}
// default(type)
if (initializerExpression.IsKind(SyntaxKind.DefaultExpression))
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册