提交 1ce46dd4 编写于 作者: C CyrusNajmabadi

Respect user options around string/String when generating parameter check.

上级 ee4eec9d
......@@ -705,6 +705,7 @@ public C(string s)
}", index: 2);
}
[WorkItem(19173, "https://github.com/dotnet/roslyn/issues/19173")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)]
public async Task TestMissingOnUnboundTypeWithExistingNullCheck()
{
......@@ -721,5 +722,38 @@ public C(String [||]s)
}
}");
}
[WorkItem(19174, "https://github.com/dotnet/roslyn/issues/19174")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)]
public async Task TestRespectPredefinedTypePreferences()
{
await TestInRegularAndScript1Async(
@"
using System;
class Program
{
static void Main([||]String bar)
{
}
}",
@"
using System;
class Program
{
static void Main(String bar)
{
if (String.IsNullOrEmpty(bar))
{
throw new ArgumentException(""message"", nameof(bar));
}
}
}", index: 1,
parameters: new TestParameters(
options: Option(
CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess,
CodeStyleOptions.FalseWithSuggestionEnforcement)));
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Composition;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.InitializeParameter;
using Microsoft.CodeAnalysis.Semantics;
namespace Microsoft.CodeAnalysis.CSharp.InitializeParameter
{
......
......@@ -241,11 +241,13 @@ private bool IsNullLiteral(IOperation operand)
Compilation compilation, SyntaxGenerator generator,
IParameterSymbol parameter, string methodName)
{
var stringType = compilation.GetSpecialType(SpecialType.System_String);
// generates: if (string.IsXXX(s)) throw new ArgumentException("message", nameof(s))
return (TStatementSyntax)generator.IfStatement(
generator.InvocationExpression(
generator.MemberAccessExpression(
generator.TypeExpression(SpecialType.System_String),
generator.TypeExpression(stringType),
generator.IdentifierName(methodName)),
generator.Argument(generator.IdentifierName(parameter.Name))),
SpecializedCollections.SingletonEnumerable(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册