diff --git a/ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs b/ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs index 513496c699..f22091776a 100644 --- a/ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs +++ b/ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs @@ -1356,7 +1356,7 @@ namespace ICSharpCode.NRefactory.CSharp CodeObject IAstVisitor.VisitPreProcessorDirective (PreProcessorDirective preProcessorDirective) { - return new CodeComment ("#" + preProcessorDirective.Type.ToString ().ToLower ()); + return new CodeComment ("#" + preProcessorDirective.Type.ToString ().ToLowerInvariant ()); } CodeObject IAstVisitor.VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration) diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/AddAnotherAccessorAction.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/AddAnotherAccessorAction.cs index b093880e66..69384a1278 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/AddAnotherAccessorAction.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/AddAnotherAccessorAction.cs @@ -73,7 +73,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring { if (pdecl.Setter.IsNull && !pdecl.Getter.IsNull) { var field = RemoveBackingStoreAction.ScanGetter (context, pdecl); - if (field != null) + if (field != null && !field.IsReadOnly && !field.IsConst) return new ExpressionStatement (new AssignmentExpression (new IdentifierExpression (field.Name), AssignmentOperatorType.Assign, new IdentifierExpression ("value"))); } diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/RemoveBackingStoreAction.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/RemoveBackingStoreAction.cs index 6267e0c558..4e1add9b5f 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/RemoveBackingStoreAction.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/RemoveBackingStoreAction.cs @@ -89,7 +89,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring var setterField = ScanSetter (context, propertyDeclaration); if (setterField == null) return null; - if (getterField.Region != setterField.Region) + if (!getterField.Equals(setterField)) return null; return getterField; } diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ConstantConditionIssue.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ConstantConditionIssue.cs index f3d639be49..aac9409f8b 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ConstantConditionIssue.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ConstantConditionIssue.cs @@ -95,7 +95,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring var value = (bool)resolveResult.ConstantValue; var conditionalExpr = condition.Parent as ConditionalExpression; var ifElseStatement = condition.Parent as IfElseStatement; - var valueStr = value.ToString ().ToLower (); + var valueStr = value.ToString ().ToLowerInvariant (); CodeAction action; if (conditionalExpr != null) { diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddAnotherAccessorTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddAnotherAccessorTests.cs index 5f0369cbce..5e0bd1ae9d 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddAnotherAccessorTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddAnotherAccessorTests.cs @@ -64,6 +64,37 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions "}", result); } + [Test] + public void TestAddSet_ReadOnlyField () + { + string result = RunContextAction ( + new AddAnotherAccessorAction (), + "class TestClass" + Environment.NewLine + + "{" + Environment.NewLine + + " readonly int field;" + Environment.NewLine + + " public int $Field {" + Environment.NewLine + + " get {" + Environment.NewLine + + " return field;" + Environment.NewLine + + " }" + Environment.NewLine + + " }" + Environment.NewLine + + "}" + ); + + Assert.AreEqual ( + "class TestClass" + Environment.NewLine + + "{" + Environment.NewLine + + " readonly int field;" + Environment.NewLine + + " public int Field {" + Environment.NewLine + + " get {" + Environment.NewLine + + " return field;" + Environment.NewLine + + " }" + Environment.NewLine + + " set {" + Environment.NewLine + + " throw new System.NotImplementedException ();" + Environment.NewLine + + " }" + Environment.NewLine + + " }" + Environment.NewLine + + "}", result); + } + [Test] public void TestAddGet () {