From 43a189792a3c0adb170afac3f48ec0da344114d5 Mon Sep 17 00:00:00 2001 From: hrrrrustic Date: Mon, 12 Apr 2021 16:10:04 +0300 Subject: [PATCH] readonly annotation --- ...em.Diagnostics.DiagnosticSourceActivity.cs | 2 +- .../src/System/Diagnostics/Activity.cs | 2 +- .../Diagnostics/ActivityTagsCollection.cs | 2 +- .../ref/System.Diagnostics.Tracing.cs | 14 ++++++------ .../Diagnostics/Tracing/EventDescriptor.cs | 22 +++++++++---------- .../System/Diagnostics/Tracing/EventSource.cs | 10 ++++----- .../Tracing/TraceLogging/ConcurrentSet.cs | 2 +- .../TraceLogging/EventSourceOptions.cs | 12 +++++----- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs index 9402388ca45b93..a93b2d9fb24578 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs @@ -101,7 +101,7 @@ public class ActivityTagsCollection : System.Collections.Generic.IDictionary>, System.Collections.IEnumerator { - public System.Collections.Generic.KeyValuePair Current { get { throw null; } } + public readonly System.Collections.Generic.KeyValuePair Current { get { throw null; } } object System.Collections.IEnumerator.Current { get { throw null; } } public void Dispose() { throw null; } public bool MoveNext() { throw null; } diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs index b2d2cd0b20264c..a625036b18d49d 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs @@ -1674,7 +1674,7 @@ public Enumerator(LinkedListNode? head) _currentItem = default; } - public T Current => _currentItem!; + public readonly T Current => _currentItem!; object? IEnumerator.Current => Current; diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityTagsCollection.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityTagsCollection.cs index 55accdb5ed463b..11f6c6b0f1b140 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityTagsCollection.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityTagsCollection.cs @@ -286,7 +286,7 @@ public struct Enumerator : IEnumerator>, IEnumerat private List>.Enumerator _enumerator; internal Enumerator(List> list) => _enumerator = list.GetEnumerator(); - public KeyValuePair Current => _enumerator.Current; + public readonly KeyValuePair Current => _enumerator.Current; object IEnumerator.Current => ((IEnumerator)_enumerator).Current; public void Dispose() => _enumerator.Dispose(); public bool MoveNext() => _enumerator.MoveNext(); diff --git a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs index ae1f677c256374..a88c2590250192 100644 --- a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs +++ b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs @@ -218,8 +218,8 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, System.Gu protected internal partial struct EventData { private int _dummyPrimitive; - public System.IntPtr DataPointer { get { throw null; } set { } } - public int Size { get { throw null; } set { } } + public System.IntPtr DataPointer { readonly get { throw null; } set { } } + public int Size { readonly get { throw null; } set { } } } } [System.AttributeUsageAttribute(System.AttributeTargets.Class)] @@ -246,11 +246,11 @@ public EventSourceException(string? message, System.Exception? innerException) { public partial struct EventSourceOptions { private int _dummyPrimitive; - public System.Diagnostics.Tracing.EventActivityOptions ActivityOptions { get { throw null; } set { } } - public System.Diagnostics.Tracing.EventKeywords Keywords { get { throw null; } set { } } - public System.Diagnostics.Tracing.EventLevel Level { get { throw null; } set { } } - public System.Diagnostics.Tracing.EventOpcode Opcode { get { throw null; } set { } } - public System.Diagnostics.Tracing.EventTags Tags { get { throw null; } set { } } + public System.Diagnostics.Tracing.EventActivityOptions ActivityOptions { readonly get { throw null; } set { } } + public System.Diagnostics.Tracing.EventKeywords Keywords { readonly get { throw null; } set { } } + public System.Diagnostics.Tracing.EventLevel Level { readonly get { throw null; } set { } } + public System.Diagnostics.Tracing.EventOpcode Opcode { readonly get { throw null; } set { } } + public System.Diagnostics.Tracing.EventTags Tags { readonly get { throw null; } set { } } } [System.FlagsAttribute] public enum EventSourceSettings diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventDescriptor.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventDescriptor.cs index c3994e613a3160..30a4e0035cfbb7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventDescriptor.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventDescriptor.cs @@ -94,23 +94,23 @@ long keywords m_task = (ushort)task; } - public int EventId => m_id; - public byte Version => m_version; - public byte Channel => m_channel; - public byte Level => m_level; - public byte Opcode => m_opcode; - public int Task => m_task; - public long Keywords => m_keywords; + public readonly int EventId => m_id; + public readonly byte Version => m_version; + public readonly byte Channel => m_channel; + public readonly byte Level => m_level; + public readonly byte Opcode => m_opcode; + public readonly int Task => m_task; + public readonly long Keywords => m_keywords; - internal int TraceLoggingId => m_traceloggingId; + internal readonly int TraceLoggingId => m_traceloggingId; - public override bool Equals([NotNullWhen(true)] object? obj) => + public override readonly bool Equals([NotNullWhen(true)] object? obj) => obj is EventDescriptor ed && Equals(ed); - public override int GetHashCode() => + public override readonly int GetHashCode() => m_id ^ m_version ^ m_channel ^ m_level ^ m_opcode ^ m_task ^ (int)m_keywords; - public bool Equals(EventDescriptor other) => + public readonly bool Equals(EventDescriptor other) => m_id == other.m_id && m_version == other.m_version && m_channel == other.m_channel && diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index ff9278b4a49eba..e0303cd6dcf8f9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -1178,7 +1178,7 @@ protected internal struct EventData /// public unsafe IntPtr DataPointer { - get => (IntPtr)(void*)m_Ptr; + readonly get => (IntPtr)(void*)m_Ptr; set => m_Ptr = unchecked((ulong)(void*)value); } @@ -1187,7 +1187,7 @@ public unsafe IntPtr DataPointer /// public int Size { - get => m_Size; + readonly get => m_Size; set => m_Size = value; } @@ -1197,7 +1197,7 @@ public int Size /// internal int Reserved { - get => m_Reserved; + readonly get => m_Reserved; set => m_Reserved = value; } @@ -5054,7 +5054,7 @@ public SessionMask(SessionMask m) public SessionMask(uint mask = 0) { m_mask = mask & MASK; } - public bool IsEqualOrSupersetOf(SessionMask m) + public readonly bool IsEqualOrSupersetOf(SessionMask m) { return (this.m_mask | m.m_mask) == this.m_mask; } @@ -5067,7 +5067,7 @@ public static SessionMask FromId(int perEventSourceSessionId) return new SessionMask((uint)1 << perEventSourceSessionId); } - public ulong ToEventKeywords() + public readonly ulong ToEventKeywords() { return (ulong)m_mask << SHIFT_SESSION_TO_KEYWORD; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs index a7fd4fabbd7852..1cc0d5b9193e9d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs @@ -29,7 +29,7 @@ internal struct ConcurrentSet { private ItemType[]? items; - public ItemType? TryGet(KeyType key) + public readonly ItemType? TryGet(KeyType key) { ItemType? item; ItemType[]? oldItems = this.items; diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceOptions.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceOptions.cs index 1d0dcf4cc0348b..f632be47ad418d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceOptions.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceOptions.cs @@ -37,7 +37,7 @@ public struct EventSourceOptions /// public EventLevel Level { - get => (EventLevel)this.level; + readonly get => (EventLevel)this.level; set { this.level = checked((byte)value); @@ -51,7 +51,7 @@ public EventLevel Level /// public EventOpcode Opcode { - get => (EventOpcode)this.opcode; + readonly get => (EventOpcode)this.opcode; set { this.opcode = checked((byte)value); @@ -59,7 +59,7 @@ public EventOpcode Opcode } } - internal bool IsOpcodeSet => (this.valuesSet & opcodeSet) != 0; + internal readonly bool IsOpcodeSet => (this.valuesSet & opcodeSet) != 0; /// /// Gets or sets the keywords to use for the specified event. If this @@ -67,7 +67,7 @@ public EventOpcode Opcode /// public EventKeywords Keywords { - get => this.keywords; + readonly get => this.keywords; set { this.keywords = value; @@ -81,7 +81,7 @@ public EventKeywords Keywords /// public EventTags Tags { - get => this.tags; + readonly get => this.tags; set { this.tags = value; @@ -95,7 +95,7 @@ public EventTags Tags /// public EventActivityOptions ActivityOptions { - get => this.activityOptions; + readonly get => this.activityOptions; set { this.activityOptions = value;