|
|
@ -26,6 +26,8 @@ |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq; |
|
|
|
using ICSharpCode.NRefactory.PatternMatching; |
|
|
|
using ICSharpCode.NRefactory.PatternMatching; |
|
|
|
|
|
|
|
using ICSharpCode.NRefactory.TypeSystem; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
|
|
|
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
|
|
|
{ |
|
|
|
{ |
|
|
@ -33,7 +35,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring |
|
|
|
{ |
|
|
|
{ |
|
|
|
public bool IsValid (RefactoringContext context) |
|
|
|
public bool IsValid (RefactoringContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return GetVariableDeclarationStatement (context) != null; |
|
|
|
var varDecl = GetVariableDeclarationStatement (context); |
|
|
|
|
|
|
|
if (varDecl == null) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
var type = context.Resolve (varDecl.Variables.First ().Initializer).Type; |
|
|
|
|
|
|
|
return !type.Equals (SharedTypes.Null) && !type.Equals (SharedTypes.UnknownType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Run (RefactoringContext context) |
|
|
|
public void Run (RefactoringContext context) |
|
|
@ -41,7 +47,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring |
|
|
|
var varDecl = GetVariableDeclarationStatement (context); |
|
|
|
var varDecl = GetVariableDeclarationStatement (context); |
|
|
|
|
|
|
|
|
|
|
|
using (var script = context.StartScript ()) { |
|
|
|
using (var script = context.StartScript ()) { |
|
|
|
script.Replace (varDecl.Type, context.CreateShortType (context.Resolve (varDecl.Variables.First ().Initializer).Type.ConvertToAstType ())); |
|
|
|
var type = context.Resolve (varDecl.Variables.First ().Initializer).Type; |
|
|
|
|
|
|
|
script.Replace (varDecl.Type, context.CreateShortType (type)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|