diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/ObjectPools/PooledObject`1.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/ObjectPools/PooledObject`1.cs index 3bc8b0822..aff5a5891 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/ObjectPools/PooledObject`1.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/ObjectPools/PooledObject`1.cs @@ -29,7 +29,7 @@ public PooledObject(ObjectPool pool, Func, T> allocator, Action this.releaser = releaser; } - public T Object + public readonly T Object { get { diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/TriviaHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/TriviaHelper.cs index 5563cd920..9ad5a4eb6 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/TriviaHelper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/TriviaHelper.cs @@ -522,7 +522,7 @@ private static int BinarySearch(SyntaxTriviaList leadingTrivia, SyntaxTrivia tri /// /// Helper class that merges two SyntaxTriviaLists with (hopefully) the lowest possible performance penalty. /// - internal struct DualTriviaListHelper : IReadOnlyList + internal readonly struct DualTriviaListHelper : IReadOnlyList { private readonly SyntaxTriviaList part1; private readonly int part1Count; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonValue.cs b/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonValue.cs index 842515c3c..10af037ab 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonValue.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonValue.cs @@ -151,7 +151,7 @@ private JsonValue(JsonValueType type, double value, object reference) /// Gets the type of this JsonValue. /// /// The type of this JsonValue. - public JsonValueType Type + public readonly JsonValueType Type { get { @@ -163,7 +163,7 @@ public JsonValueType Type /// Gets a value indicating whether this JsonValue is Null. /// /// A value indicating whether this JsonValue is Null. - public bool IsNull + public readonly bool IsNull { get { @@ -175,7 +175,7 @@ public bool IsNull /// Gets a value indicating whether this JsonValue is a Boolean. /// /// A value indicating whether this JsonValue is a Boolean. - public bool IsBoolean + public readonly bool IsBoolean { get { @@ -187,7 +187,7 @@ public bool IsBoolean /// Gets a value indicating whether this JsonValue is an Integer. /// /// A value indicating whether this JsonValue is an Integer. - public bool IsInteger + public readonly bool IsInteger { get { @@ -205,7 +205,7 @@ public bool IsInteger /// Gets a value indicating whether this JsonValue is a Number. /// /// A value indicating whether this JsonValue is a Number. - public bool IsNumber + public readonly bool IsNumber { get { @@ -217,7 +217,7 @@ public bool IsNumber /// Gets a value indicating whether this JsonValue is a String. /// /// A value indicating whether this JsonValue is a String. - public bool IsString + public readonly bool IsString { get { @@ -229,7 +229,7 @@ public bool IsString /// Gets a value indicating whether this JsonValue is a JsonObject. /// /// A value indicating whether this JsonValue is a JsonObject. - public bool IsJsonObject + public readonly bool IsJsonObject { get { @@ -241,7 +241,7 @@ public bool IsJsonObject /// Gets a value indicating whether this JsonValue is a JsonArray. /// /// A value indicating whether this JsonValue is a JsonArray. - public bool IsJsonArray + public readonly bool IsJsonArray { get { @@ -253,7 +253,7 @@ public bool IsJsonArray /// Gets a value indicating whether this JsonValue represents a DateTime. /// /// A value indicating whether this JsonValue represents a DateTime. - public bool IsDateTime + public readonly bool IsDateTime { get { @@ -265,7 +265,7 @@ public bool IsDateTime /// Gets a value indicating whether this value is true or false. /// /// This value as a Boolean type. - public bool AsBoolean + public readonly bool AsBoolean { get { @@ -294,7 +294,7 @@ public bool AsBoolean /// Gets this value as an Integer type. /// /// This value as an Integer type. - public int AsInteger + public readonly int AsInteger { get { @@ -319,7 +319,7 @@ public int AsInteger /// Gets this value as a Number type. /// /// This value as a Number type. - public double AsNumber + public readonly double AsNumber { get { @@ -354,7 +354,7 @@ public double AsNumber /// Gets this value as a String type. /// /// This value as a String type. - public string AsString + public readonly string AsString { get { @@ -381,7 +381,7 @@ public string AsString /// Gets this value as an JsonObject. /// /// This value as an JsonObject. - public JsonObject AsJsonObject + public readonly JsonObject AsJsonObject { get { @@ -395,7 +395,7 @@ public JsonObject AsJsonObject /// Gets this value as an JsonArray. /// /// This value as an JsonArray. - public JsonArray AsJsonArray + public readonly JsonArray AsJsonArray { get { @@ -409,7 +409,7 @@ public JsonArray AsJsonArray /// Gets this value as a system.DateTime. /// /// This value as a system.DateTime. - public DateTime? AsDateTime + public readonly DateTime? AsDateTime { get { @@ -430,7 +430,7 @@ public DateTime? AsDateTime /// Gets this (inner) value as a System.object. /// /// This (inner) value as a System.object. - public object AsObject + public readonly object AsObject { get { @@ -458,7 +458,7 @@ public object AsObject /// /// Thrown when this JsonValue is not a JsonObject. /// - public JsonValue this[string key] + public readonly JsonValue this[string key] { get { @@ -492,7 +492,7 @@ public JsonValue this[string key] /// /// Thrown when this is not a . /// - public JsonValue this[int index] + public readonly JsonValue this[int index] { get { @@ -813,7 +813,7 @@ public static JsonValue Parse(string text) } /// - public override bool Equals(object obj) + public override readonly bool Equals(object obj) { if (obj == null) { @@ -832,7 +832,7 @@ public override bool Equals(object obj) } /// - public override int GetHashCode() + public override readonly int GetHashCode() { if (this.IsNull) { diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SeparatedSyntaxListWrapper`1.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SeparatedSyntaxListWrapper`1.cs index 3e7f2f000..7e2cd4669 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SeparatedSyntaxListWrapper`1.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SeparatedSyntaxListWrapper`1.cs @@ -172,11 +172,11 @@ public Enumerator(SeparatedSyntaxListWrapper wrapper) this.current = default; } - public TNode Current => this.current; + public readonly TNode Current => this.current; - object IEnumerator.Current => this.Current; + readonly object IEnumerator.Current => this.Current; - public override bool Equals(object obj) + public override readonly bool Equals(object obj) { Enumerator? otherOpt = obj as Enumerator?; if (!otherOpt.HasValue) @@ -189,7 +189,7 @@ public override bool Equals(object obj) && other.index == this.index; } - public override int GetHashCode() + public override readonly int GetHashCode() { if (this.wrapper == null) { @@ -199,7 +199,7 @@ public override int GetHashCode() return this.wrapper.GetHashCode() ^ this.index; } - public void Dispose() + public readonly void Dispose() { } diff --git a/StyleCop.Analyzers/StyleCopTester/Program.cs b/StyleCop.Analyzers/StyleCopTester/Program.cs index a259cded4..0ad1b99b6 100644 --- a/StyleCop.Analyzers/StyleCopTester/Program.cs +++ b/StyleCop.Analyzers/StyleCopTester/Program.cs @@ -608,7 +608,7 @@ private static void PrintHelp() Console.WriteLine("/edititer: Specifies the number of iterations to use for testing documents with /editperf. When this is not specified, the default value is 10."); } - private struct DocumentAnalyzerPerformance + private readonly struct DocumentAnalyzerPerformance { public DocumentAnalyzerPerformance(double editsPerSecond) { diff --git a/StyleCop.Analyzers/StyleCopTester/Statistic.cs b/StyleCop.Analyzers/StyleCopTester/Statistic.cs index bb7151a07..432308d7e 100644 --- a/StyleCop.Analyzers/StyleCopTester/Statistic.cs +++ b/StyleCop.Analyzers/StyleCopTester/Statistic.cs @@ -5,7 +5,7 @@ namespace StyleCopTester { - internal struct Statistic + internal readonly struct Statistic { public Statistic(int numberOfNodes, int numberOfTokens, int numberOfTrivia) {