diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs index b969b8ba55..e246924dd3 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs @@ -454,6 +454,8 @@ namespace ICSharpCode.TextEditor int FindWordEnd(IDocument document, int offset) { LineSegment line = document.GetLineSegmentForOffset(offset); + if (line.Length == 0) + return offset; int endPos = line.Offset + line.Length; offset = Math.Min(offset, endPos - 1); diff --git a/src/Main/Core/Project/Src/Services/PropertyService/Properties.cs b/src/Main/Core/Project/Src/Services/PropertyService/Properties.cs index a0ac92bf41..9a217841f3 100644 --- a/src/Main/Core/Project/Src/Services/PropertyService/Properties.cs +++ b/src/Main/Core/Project/Src/Services/PropertyService/Properties.cs @@ -9,6 +9,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; +using System.Globalization; using System.IO; using System.Text; using System.Xml; @@ -64,7 +65,7 @@ namespace ICSharpCode.Core public string this[string property] { get { - return Convert.ToString(Get(property)); + return Convert.ToString(Get(property), CultureInfo.InvariantCulture); } set { Set(property, value); diff --git a/src/Main/Core/Project/Src/Services/StringParser/StringParser.cs b/src/Main/Core/Project/Src/Services/StringParser/StringParser.cs index a3fbab25dd..2c0b0590ac 100644 --- a/src/Main/Core/Project/Src/Services/StringParser/StringParser.cs +++ b/src/Main/Core/Project/Src/Services/StringParser/StringParser.cs @@ -100,7 +100,7 @@ namespace ICSharpCode.Core StringBuilder output = null; // don't use StringBuilder if input is a single property do { int oldPos = pos; - pos = input.IndexOf("${", pos); + pos = input.IndexOf("${", pos, StringComparison.Ordinal); if (pos < 0) { if (output == null) { return input; @@ -149,7 +149,7 @@ namespace ICSharpCode.Core // most properties start with res: in lowercase, // so we can save 2 string allocations here, in addition to all the jumps // All other prefixed properties {prefix:Key} shoulg get handled in the switch below. - if (propertyName.StartsWith("res:")) { + if (propertyName.StartsWith("res:", StringComparison.OrdinalIgnoreCase)) { try { return Parse(ResourceService.GetString(propertyName.Substring(4)), customTags); } catch (ResourceNotFoundException) { @@ -235,7 +235,7 @@ namespace ICSharpCode.Core static string GetProperty(string propertyName) { string defaultValue = ""; - int pos = propertyName.LastIndexOf("??"); + int pos = propertyName.LastIndexOf("??", StringComparison.Ordinal); if (pos >= 0) { defaultValue = propertyName.Substring(pos + 2); propertyName = propertyName.Substring(0, pos); diff --git a/src/Main/ICSharpCode.SharpDevelop.BuildWorker/BuildJob.cs b/src/Main/ICSharpCode.SharpDevelop.BuildWorker/BuildJob.cs index 428ac2d20b..3002226b46 100644 --- a/src/Main/ICSharpCode.SharpDevelop.BuildWorker/BuildJob.cs +++ b/src/Main/ICSharpCode.SharpDevelop.BuildWorker/BuildJob.cs @@ -50,7 +50,7 @@ namespace ICSharpCode.SharpDevelop.BuildWorker get { return additionalImports; } } - HashSet interestingTaskNames = new HashSet(StringComparer.InvariantCultureIgnoreCase); + HashSet interestingTaskNames = new HashSet(StringComparer.OrdinalIgnoreCase); public ICollection InterestingTaskNames { get { return interestingTaskNames; } diff --git a/src/Main/ICSharpCode.SharpDevelop.BuildWorker/Program.cs b/src/Main/ICSharpCode.SharpDevelop.BuildWorker/Program.cs index 1c1bc11d8e..3452051b61 100644 --- a/src/Main/ICSharpCode.SharpDevelop.BuildWorker/Program.cs +++ b/src/Main/ICSharpCode.SharpDevelop.BuildWorker/Program.cs @@ -10,12 +10,14 @@ using System; using System.Collections.Generic; -using System.IO; using System.Diagnostics; +using System.IO; +using System.Runtime.Serialization; using System.Threading; + using ICSharpCode.SharpDevelop.BuildWorker.Interprocess; -using Microsoft.Build.Framework; using Microsoft.Build.BuildEngine; +using Microsoft.Build.Framework; namespace ICSharpCode.SharpDevelop.BuildWorker { @@ -107,7 +109,8 @@ namespace ICSharpCode.SharpDevelop.BuildWorker } // Called with CallMethodOnWorker - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + //[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + // TODO: make use of CancelBuild public void CancelBuild() { lock (this) { @@ -442,6 +445,14 @@ namespace ICSharpCode.SharpDevelop.BuildWorker [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1064:ExceptionsShouldBePublic")] sealed class BuildCancelException : Exception { + public BuildCancelException() + { + } + + BuildCancelException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } } } } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Ambience.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Ambience.cs index 0421567780..cc88f227cc 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Ambience.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Ambience.cs @@ -116,7 +116,7 @@ namespace ICSharpCode.SharpDevelop.Dom { #if DEBUG if (ownerThread != System.Threading.Thread.CurrentThread.ManagedThreadId) - throw new Exception("Ambience may only be used by the thread that created it"); + throw new InvalidOperationException("Ambience may only be used by the thread that created it"); #endif } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ExpressionContext.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ExpressionContext.cs index 250771de81..1bb7dad999 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ExpressionContext.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ExpressionContext.cs @@ -62,104 +62,104 @@ namespace ICSharpCode.SharpDevelop.Dom #region C# specific contexts (public static fields) * MOVE TO ANOTHER CLASS * /// The context expects a new identifier /// class *expr* {}; string *expr*; - public static ExpressionContext IdentifierExpected = new DefaultExpressionContext("IdentifierExpected"); + public readonly static ExpressionContext IdentifierExpected = new DefaultExpressionContext("IdentifierExpected"); /// The context is outside of any type declaration, expecting a global-level keyword. - public static ExpressionContext Global = new DefaultExpressionContext("Global"); + public readonly static ExpressionContext Global = new DefaultExpressionContext("Global"); /// The context is the body of a property declaration. /// string Name { *expr* } - public static ExpressionContext PropertyDeclaration = new DefaultExpressionContext("PropertyDeclaration"); + public readonly static ExpressionContext PropertyDeclaration = new DefaultExpressionContext("PropertyDeclaration"); /// The context is the body of a property declaration inside an interface. /// string Name { *expr* } - public static ExpressionContext InterfacePropertyDeclaration = new DefaultExpressionContext("InterfacePropertyDeclaration"); + public readonly static ExpressionContext InterfacePropertyDeclaration = new DefaultExpressionContext("InterfacePropertyDeclaration"); /// The context is the body of a event declaration. /// event EventHandler NameChanged { *expr* } - public static ExpressionContext EventDeclaration = new DefaultExpressionContext("EventDeclaration"); + public readonly static ExpressionContext EventDeclaration = new DefaultExpressionContext("EventDeclaration"); /// The context is the body of a method. /// void Main () { *expr* } - public static ExpressionContext MethodBody = new DefaultExpressionContext("MethodBody"); + public readonly static ExpressionContext MethodBody = new DefaultExpressionContext("MethodBody"); /// The context is after the type parameters of a type/method declaration. /// The only valid keyword is "where" /// class <T> *expr* - public static ExpressionContext ConstraintsStart = new DefaultExpressionContext("ConstraintsStart"); + public readonly static ExpressionContext ConstraintsStart = new DefaultExpressionContext("ConstraintsStart"); /// The context is after the 'where' of a constraints list. /// class <T> where *expr* - public static ExpressionContext Constraints = new NonStaticTypeExpressionContext("Constraints", false); + public readonly static ExpressionContext Constraints = new NonStaticTypeExpressionContext("Constraints", false); /// The context is the body of a type declaration. - public static ExpressionContext TypeDeclaration = new NonStaticTypeExpressionContext("TypeDeclaration", true); + public readonly static ExpressionContext TypeDeclaration = new NonStaticTypeExpressionContext("TypeDeclaration", true); /// The context is the body of an interface declaration. - public static ExpressionContext InterfaceDeclaration = new NonStaticTypeExpressionContext("InterfaceDeclaration", true); + public readonly static ExpressionContext InterfaceDeclaration = new NonStaticTypeExpressionContext("InterfaceDeclaration", true); /// Context expects "base" or "this". /// public ClassName() : *expr* - public static ExpressionContext BaseConstructorCall = new DefaultExpressionContext("BaseConstructorCall"); + public readonly static ExpressionContext BaseConstructorCall = new DefaultExpressionContext("BaseConstructorCall"); /// The first parameter /// void MethodName(*expr*) - public static ExpressionContext FirstParameterType = new NonStaticTypeExpressionContext("FirstParameterType", false); + public readonly static ExpressionContext FirstParameterType = new NonStaticTypeExpressionContext("FirstParameterType", false); /// Another parameter /// void MethodName(..., *expr*) - public static ExpressionContext ParameterType = new NonStaticTypeExpressionContext("ParameterType", false); + public readonly static ExpressionContext ParameterType = new NonStaticTypeExpressionContext("ParameterType", false); /// Context expects a fully qualified type name. /// using Alias = *expr*; - public static ExpressionContext FullyQualifiedType = new DefaultExpressionContext("FullyQualifiedType"); + public readonly static ExpressionContext FullyQualifiedType = new DefaultExpressionContext("FullyQualifiedType"); /// Context expects is a property name in an object initializer. /// new *type* [(args)] { *expr* = ... } - public static ExpressionContext ObjectInitializer = new DefaultExpressionContext("ObjectInitializer"); + public readonly static ExpressionContext ObjectInitializer = new DefaultExpressionContext("ObjectInitializer"); #endregion #region Default contexts (public static fields) /// Default/unknown context - public static ExpressionContext Default = new DefaultExpressionContext("Default"); + public readonly static ExpressionContext Default = new DefaultExpressionContext("Default"); /// The context expects the base type of an enum. /// enum Name : *expr* {} - public static ExpressionContext EnumBaseType = new EnumBaseTypeExpressionContext(); + public readonly static ExpressionContext EnumBaseType = new EnumBaseTypeExpressionContext(); /// Context expects a non-sealed type or interface /// class C : *expr* {} - public static ExpressionContext InheritableType = new InheritableTypeExpressionContext(); + public readonly static ExpressionContext InheritableType = new InheritableTypeExpressionContext(); /// Context expects a namespace name /// using *expr*; - public static ExpressionContext Namespace = new ImportableExpressionContext(false); + public readonly static ExpressionContext Namespace = new ImportableExpressionContext(false); /// Context expects an importable type (namespace or class with public static members) /// Imports *expr*; - public static ExpressionContext Importable = new ImportableExpressionContext(true); + public readonly static ExpressionContext Importable = new ImportableExpressionContext(true); /// Context expects a type name /// typeof(*expr*) - public static ExpressionContext Type = new TypeExpressionContext(null, false, true); + public readonly static ExpressionContext Type = new TypeExpressionContext(null, false, true); /// Context expects the name of a non-static, non-void type /// is *expr*, *expr* variableName - public static ExpressionContext NonStaticNonVoidType = new NonStaticTypeExpressionContext("NonStaticType", false); + public readonly static ExpressionContext NonStaticNonVoidType = new NonStaticTypeExpressionContext("NonStaticType", false); /// Context expects a non-abstract type that has accessible constructors /// new *expr*(); /// When using this context, a resolver should treat the expression as object creation, /// even when the keyword "new" is not part of the expression. - public static ExpressionContext ObjectCreation = new TypeExpressionContext(null, true, true); + public readonly static ExpressionContext ObjectCreation = new TypeExpressionContext(null, true, true); /// Context expects a type deriving from System.Attribute. /// [*expr*()] /// When using this context, a resolver should try resolving typenames with an /// appended "Attribute" suffix and treat "invocations" of the attribute type as /// object creation. - public static ExpressionContext Attribute = new AttributeExpressionContext(); + public readonly static ExpressionContext Attribute = new AttributeExpressionContext(); /// Context expects a type name which has special base type /// The class the expression must derive from. @@ -173,11 +173,11 @@ namespace ICSharpCode.SharpDevelop.Dom /// Context expects an interface /// interface C : *expr* {} /// Implements *expr* - public static ExpressionContext Interface = new ClassTypeExpressionContext(ClassType.Interface); + public readonly static ExpressionContext Interface = new ClassTypeExpressionContext(ClassType.Interface); /// Context expects a delegate /// public event *expr* - public static ExpressionContext DelegateType = new ClassTypeExpressionContext(ClassType.Delegate); + public readonly static ExpressionContext DelegateType = new ClassTypeExpressionContext(ClassType.Delegate); #endregion diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultMethod.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultMethod.cs index bab90c8a7e..95e4486a5b 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultMethod.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultMethod.cs @@ -195,13 +195,9 @@ namespace ICSharpCode.SharpDevelop.Dom public virtual int CompareTo(IMethod value) { - int cmp; - - if (FullyQualifiedName != null) { - cmp = FullyQualifiedName.CompareTo(value.FullyQualifiedName); - if (cmp != 0) { - return cmp; - } + int cmp = string.CompareOrdinal(this.FullyQualifiedName, value.FullyQualifiedName); + if (cmp != 0) { + return cmp; } cmp = this.TypeParameters.Count - value.TypeParameters.Count; diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultProperty.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultProperty.cs index c2cae7e092..d2f9719816 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultProperty.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultProperty.cs @@ -94,25 +94,25 @@ namespace ICSharpCode.SharpDevelop.Dom { public DomRegion GetterRegion { get { return getterRegion; } - set { + set { CheckBeforeMutation(); - getterRegion = value; + getterRegion = value; } } public DomRegion SetterRegion { get { return setterRegion; } - set { + set { CheckBeforeMutation(); - setterRegion = value; + setterRegion = value; } } public ModifierEnum GetterModifiers { get { return getterModifiers; } - set { + set { CheckBeforeMutation(); - getterModifiers = value; + getterModifiers = value; } } @@ -120,7 +120,7 @@ namespace ICSharpCode.SharpDevelop.Dom { get { return setterModifiers; } set { CheckBeforeMutation(); - setterModifiers = value; + setterModifiers = value; } } @@ -138,13 +138,9 @@ namespace ICSharpCode.SharpDevelop.Dom { public virtual int CompareTo(IProperty value) { - int cmp; - - if (FullyQualifiedName != null) { - cmp = FullyQualifiedName.CompareTo(value.FullyQualifiedName); - if (cmp != 0) { - return cmp; - } + int cmp = string.CompareOrdinal(this.FullyQualifiedName, value.FullyQualifiedName); + if (cmp != 0) { + return cmp; } return DiffUtility.Compare(Parameters, value.Parameters); diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/TypeVisitor.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/TypeVisitor.cs index 66e270ac45..4e2ac8cdcf 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/TypeVisitor.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/TypeVisitor.cs @@ -70,8 +70,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver break; } } - if (t == null && callingMember is IMethod && (callingMember as IMethod).TypeParameters != null) { - foreach (ITypeParameter tp in (callingMember as IMethod).TypeParameters) { + IMethod callingMethod = callingMember as IMethod; + if (t == null && callingMethod != null) { + foreach (ITypeParameter tp in callingMethod.TypeParameters) { if (languageProperties.NameComparer.Equals(tp.Name, reference.Type)) { t = new GenericReturnType(tp); break; @@ -80,18 +81,17 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } } if (t == null) { - if (reference.IsKeyword && reference.GenericTypes.Count == 0) { + int typeParameterCount = reference.GenericTypes.Count; + if (reference.IsKeyword) { // keyword-type like void, int, string etc. - // check GenericTypes.Count to prevent use of this code path for nullables - IClass c = projectContent.GetClass(reference.Type, 0); + IClass c = projectContent.GetClass(reference.Type, typeParameterCount); if (c != null) t = c.DefaultReturnType; else - t = new GetClassReturnType(projectContent, reference.Type, 0); + t = new GetClassReturnType(projectContent, reference.Type, typeParameterCount); } else { - int typeParameterCount = reference.GenericTypes.Count; if (useLazyReturnType || isBaseTypeReference) { - if (reference.IsGlobal || reference.IsKeyword) { + if (reference.IsGlobal) { t = new GetClassReturnType(projectContent, reference.Type, typeParameterCount); } else if (callingClass != null) { SearchClassReturnType scrt = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn, reference.Type, typeParameterCount); @@ -101,7 +101,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } } else { IClass c; - if (reference.IsGlobal || reference.IsKeyword) { + if (reference.IsGlobal) { c = projectContent.GetClass(reference.Type, typeParameterCount); t = (c != null) ? c.DefaultReturnType : null; } else if (callingClass != null) { @@ -114,9 +114,9 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver } } if (reference.GenericTypes.Count > 0) { - List para = new List(reference.GenericTypes.Count); + IReturnType[] para = new IReturnType[reference.GenericTypes.Count]; for (int i = 0; i < reference.GenericTypes.Count; ++i) { - para.Add(CreateReturnType(reference.GenericTypes[i], callingClass, callingMember, caretLine, caretColumn, projectContent, options)); + para[i] = CreateReturnType(reference.GenericTypes[i], callingClass, callingMember, caretLine, caretColumn, projectContent, options); } t = new ConstructedReturnType(t, para); } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/NRefactoryRefactoringProvider.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/NRefactoryRefactoringProvider.cs index 97ab793c07..f898c06108 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/NRefactoryRefactoringProvider.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/NRefactoryRefactoringProvider.cs @@ -608,12 +608,14 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring static bool IsEndDirective(string trimLine) { - return trimLine.StartsWith("#endregion") || trimLine.StartsWith("#endif"); + return trimLine.StartsWith("#endregion", StringComparison.Ordinal) + || trimLine.StartsWith("#endif", StringComparison.Ordinal); } static bool IsStartDirective(string trimLine) { - return trimLine.StartsWith("#region") || trimLine.StartsWith("#if"); + return trimLine.StartsWith("#region", StringComparison.Ordinal) + || trimLine.StartsWith("#if", StringComparison.Ordinal); } #endregion } diff --git a/src/Main/ICSharpCode.SharpDevelop.Sda/Src/ExceptionBox.cs b/src/Main/ICSharpCode.SharpDevelop.Sda/Src/ExceptionBox.cs index cc030c8f27..eda330c0da 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Sda/Src/ExceptionBox.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Sda/Src/ExceptionBox.cs @@ -155,11 +155,12 @@ namespace ICSharpCode.SharpDevelop.Sda void CopyInfoToClipboard() { if (copyErrorCheckBox.Checked) { + string exceptionText = exceptionTextBox.Text; if (Application.OleRequired() == ApartmentState.STA) { - ClipboardWrapper.SetText(getClipboardString()); + ClipboardWrapper.SetText(exceptionText); } else { Thread th = new Thread((ThreadStart)delegate { - ClipboardWrapper.SetText(getClipboardString()); + ClipboardWrapper.SetText(exceptionText); }); th.Name = "CopyInfoToClipboard"; th.SetApartmentState(ApartmentState.STA);