|
|
|
@ -176,6 +176,36 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
@@ -176,6 +176,36 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
|
|
|
|
|
|
|
|
|
|
internal static IEnumerable<IType> GetValidTypes(CSharpAstResolver resolver, AstNode expr) |
|
|
|
|
{ |
|
|
|
|
if (expr.Parent is IfElseStatement) { |
|
|
|
|
var parent = ((IfElseStatement)expr.Parent); |
|
|
|
|
if (parent.Condition == expr) |
|
|
|
|
return new [] { resolver.Compilation.FindType (KnownTypeCode.Boolean) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (expr.Parent is WhileStatement) { |
|
|
|
|
var parent = ((WhileStatement)expr.Parent); |
|
|
|
|
if (parent.Condition == expr) |
|
|
|
|
return new [] { resolver.Compilation.FindType (KnownTypeCode.Boolean) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (expr.Parent is ConditionalExpression) { |
|
|
|
|
var parent = ((ConditionalExpression)expr.Parent); |
|
|
|
|
if (parent.Condition == expr) |
|
|
|
|
return new [] { resolver.Compilation.FindType (KnownTypeCode.Boolean) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (expr.Parent is DoWhileStatement) { |
|
|
|
|
var parent = ((DoWhileStatement)expr.Parent); |
|
|
|
|
if (parent.Condition == expr) |
|
|
|
|
return new [] { resolver.Compilation.FindType (KnownTypeCode.Boolean) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (expr.Parent is ForStatement) { |
|
|
|
|
var parent = ((ForStatement)expr.Parent); |
|
|
|
|
if (parent.Condition == expr) |
|
|
|
|
return new [] { resolver.Compilation.FindType (KnownTypeCode.Boolean) }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (expr.Parent is DirectionExpression) { |
|
|
|
|
var parent = expr.Parent.Parent; |
|
|
|
|
if (parent is InvocationExpression) { |
|
|
|
@ -186,14 +216,14 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
@@ -186,14 +216,14 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
|
|
|
|
|
|
|
|
|
|
if (expr.Parent is ArrayInitializerExpression) { |
|
|
|
|
if (expr is NamedExpression) |
|
|
|
|
return new [] { resolver.Resolve(((NamedExpression)expr).Expression).Type }; |
|
|
|
|
return new [] { resolver.Resolve(((NamedExpression)expr).Expression).Type }; |
|
|
|
|
|
|
|
|
|
var aex = expr.Parent as ArrayInitializerExpression; |
|
|
|
|
if (aex.IsSingleElement) |
|
|
|
|
aex = aex.Parent as ArrayInitializerExpression; |
|
|
|
|
var type = GetElementType(resolver, resolver.Resolve(aex.Parent).Type); |
|
|
|
|
if (type.Kind != TypeKind.Unknown) |
|
|
|
|
return new [] { type }; |
|
|
|
|
return new [] { type }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (expr.Parent is ObjectCreateExpression) { |
|
|
|
|