提交 4b4e8965 编写于 作者: R Ravi Chande

CR feedback

上级 161e37f8
......@@ -157,17 +157,17 @@ private bool IsLambdaExpression(SemanticModel semanticModel, int position, Synta
// If we're an argument to a function with multiple overloads,
// open the builder if any overload takes a delegate at our argument position
var inferredTypes = typeInferrer.GetTypeInferenceInfo(semanticModel, position, cancellationToken: cancellationToken);
var inferredTypeInfo = typeInferrer.GetTypeInferenceInfo(semanticModel, position, cancellationToken: cancellationToken);
return inferredTypes.Any(type => GetDelegateType(type, semanticModel.Compilation).IsDelegateType());
return inferredTypeInfo.Any(type => GetDelegateType(type, semanticModel.Compilation).IsDelegateType());
}
private ITypeSymbol GetDelegateType(TypeInferenceInfo type, Compilation compilation)
private ITypeSymbol GetDelegateType(TypeInferenceInfo typeInferenceInfo, Compilation compilation)
{
ITypeSymbol typeSymbol = type.InferredType;
if (type.IsParams && type.InferredType.IsArrayType())
ITypeSymbol typeSymbol = typeInferenceInfo.InferredType;
if (typeInferenceInfo.IsParams && typeInferenceInfo.InferredType.IsArrayType())
{
typeSymbol = ((IArrayTypeSymbol)type.InferredType).ElementType;
typeSymbol = ((IArrayTypeSymbol)typeInferenceInfo.InferredType).ElementType;
}
return typeSymbol.GetDelegateType(compilation);
......
......@@ -95,20 +95,20 @@ private IEnumerable<TypeInferenceInfo> GetTypesSimple(ExpressionSyntax expressio
if (symbolInfo.CandidateReason != CandidateReason.WrongArity)
{
TypeInferenceInfo type = new TypeInferenceInfo(typeInfo.Type);
var typeInferenceInfo = new TypeInferenceInfo(typeInfo.Type);
// If it bound to a method, try to get the Action/Func form of that method.
if (type.InferredType == null &&
if (typeInferenceInfo.InferredType == null &&
symbolInfo.GetAllSymbols().Count() == 1 &&
symbolInfo.GetAllSymbols().First().Kind == SymbolKind.Method)
{
var method = symbolInfo.GetAllSymbols().First();
type = new TypeInferenceInfo(method.ConvertToType(this.Compilation));
typeInferenceInfo = new TypeInferenceInfo(method.ConvertToType(this.Compilation));
}
if (IsUsableTypeFunc(type))
if (IsUsableTypeFunc(typeInferenceInfo))
{
return SpecializedCollections.SingletonEnumerable(type);
return SpecializedCollections.SingletonEnumerable(typeInferenceInfo);
}
}
}
......@@ -1205,7 +1205,8 @@ private IEnumerable<TypeInferenceInfo> InferTypeInIfStatement(IfStatementSyntax
var addMethodParameterTypes = addMethodSymbols
.Cast<IMethodSymbol>()
.Where(a => a.Parameters.Length == initializerExpression.Expressions.Count)
.Select(a => new TypeInferenceInfo(a.Parameters.ElementAtOrDefault(parameterIndex)?.Type));
.Select(a => new TypeInferenceInfo(a.Parameters.ElementAtOrDefault(parameterIndex)?.Type))
.Where(t => t.InferredType != null);
if (addMethodParameterTypes.Any())
{
......
......@@ -101,7 +101,14 @@ public IEnumerable<ITypeSymbol> InferTypes(SemanticModel semanticModel, int posi
public IEnumerable<ITypeSymbol> InferTypes(SemanticModel semanticModel, SyntaxNode expression, CancellationToken cancellationToken)
{
return CreateTypeInferrer(semanticModel, cancellationToken).InferTypes(expression as TExpressionSyntax).Select(t => t.InferredType);
var result = new List<ITypeSymbol>();
var typeInferenceInfo = CreateTypeInferrer(semanticModel, cancellationToken).InferTypes(expression as TExpressionSyntax);
foreach (var info in typeInferenceInfo)
{
result.Add(info.InferredType);
}
return result;
}
public IEnumerable<TypeInferenceInfo> GetTypeInferenceInfo(SemanticModel semanticModel, int position, CancellationToken cancellationToken)
......
......@@ -32,14 +32,13 @@ internal interface ITypeInferenceService : ILanguageService
internal struct TypeInferenceInfo
{
private bool isParams;
public TypeInferenceInfo(ITypeSymbol type) : this()
public TypeInferenceInfo(ITypeSymbol type)
{
InferredType = type;
IsParams = false;
}
public TypeInferenceInfo(ITypeSymbol type, bool isParams) : this()
public TypeInferenceInfo(ITypeSymbol type, bool isParams)
{
InferredType = type;
IsParams = isParams;
......
'Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.Threading
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册