internal static IField GetBackingField(RefactoringContext context) { var propertyDeclaration = context.GetNode <PropertyDeclaration> (); // automatic properties always need getter & setter if (propertyDeclaration == null || propertyDeclaration.Getter.IsNull || propertyDeclaration.Setter.IsNull || propertyDeclaration.Getter.Body.IsNull || propertyDeclaration.Setter.Body.IsNull) { return(null); } if (!context.Supports(csharp3) || propertyDeclaration.HasModifier(ICSharpCode.NRefactory.CSharp.Modifiers.Abstract) || ((TypeDeclaration)propertyDeclaration.Parent).ClassType == ClassType.Interface) { return(null); } var getterField = ScanGetter(context, propertyDeclaration); if (getterField == null) { return(null); } var setterField = ScanSetter(context, propertyDeclaration); if (setterField == null) { return(null); } if (!getterField.Equals(setterField)) { return(null); } return(getterField); }
public override IEnumerable <CodeAction> GetActions(RefactoringContext context) { if (!context.Supports(minimumVersion)) { yield break; } var varDecl = GetVariableDeclarationStatement(context); var foreachStmt = GetForeachStatement(context); if (varDecl == null && foreachStmt == null) { yield break; } yield return(new CodeAction(context.TranslateString("Use 'var' keyword"), script => { if (varDecl != null) { script.Replace(varDecl.Type, new SimpleType("var")); } else { script.Replace(foreachStmt.VariableType, new SimpleType("var")); } }, (AstNode)varDecl ?? foreachStmt)); }