diff options
author | James Newton-King <james@newtonking.com> | 2022-01-20 00:01:53 +0300 |
---|---|---|
committer | James Newton-King <james@newtonking.com> | 2022-01-20 00:01:53 +0300 |
commit | 059f76450d50fa6e4525f0b66c4c36b66e637e24 (patch) | |
tree | dcf5e45c8b14d381734ea33cce0552005bb6cef2 | |
parent | ef20668b82853a123ae9cf9f66af2bf67cc56f93 (diff) |
Declare readonly members for mutable structsjamesnk/struct-readonly-members
9 files changed, 21 insertions, 21 deletions
diff --git a/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestHeaders.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestHeaders.cs index 041fc4dd6a..d16e1619f9 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestHeaders.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestHeaders.cs @@ -243,11 +243,11 @@ internal sealed partial class HttpRequestHeaders : HttpHeaders : default; } - public KeyValuePair<string, StringValues> Current => _current; + public readonly KeyValuePair<string, StringValues> Current => _current; - object IEnumerator.Current => _current; + readonly object IEnumerator.Current => _current; - public void Dispose() + public readonly void Dispose() { } diff --git a/src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseHeaders.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseHeaders.cs index 5f46fb8e3c..cd449dc37e 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseHeaders.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseHeaders.cs @@ -161,13 +161,13 @@ internal sealed partial class HttpResponseHeaders : HttpHeaders : default; } - public KeyValuePair<string, StringValues> Current => _current; + public readonly KeyValuePair<string, StringValues> Current => _current; - internal KnownHeaderType CurrentKnownType => _currentKnownType; + internal readonly KnownHeaderType CurrentKnownType => _currentKnownType; - object IEnumerator.Current => _current; + readonly object IEnumerator.Current => _current; - public void Dispose() + public readonly void Dispose() { } diff --git a/src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseTrailers.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseTrailers.cs index f4127b14de..3f39d78bda 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseTrailers.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseTrailers.cs @@ -69,13 +69,13 @@ internal partial class HttpResponseTrailers : HttpHeaders : default; } - public KeyValuePair<string, StringValues> Current => _current; + public readonly KeyValuePair<string, StringValues> Current => _current; - internal KnownHeaderType CurrentKnownType => _currentKnownType; + internal readonly KnownHeaderType CurrentKnownType => _currentKnownType; - object IEnumerator.Current => _current; + readonly object IEnumerator.Current => _current; - public void Dispose() + public readonly void Dispose() { } diff --git a/src/Servers/Kestrel/Core/src/Internal/Http/IHttpRequestLineHandler.cs b/src/Servers/Kestrel/Core/src/Internal/Http/IHttpRequestLineHandler.cs index 4e094655b2..e69874897b 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http/IHttpRequestLineHandler.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http/IHttpRequestLineHandler.cs @@ -24,13 +24,13 @@ public struct HttpVersionAndMethod public HttpVersion Version { - get => (HttpVersion)(sbyte)(byte)_versionAndMethod; + readonly get => (HttpVersion)(sbyte)(byte)_versionAndMethod; set => _versionAndMethod = (_versionAndMethod & ~0xFFul) | (byte)value; } - public HttpMethod Method => (HttpMethod)(byte)(_versionAndMethod >> 8); + public readonly HttpMethod Method => (HttpMethod)(byte)(_versionAndMethod >> 8); - public int MethodEnd => (int)(uint)(_versionAndMethod >> 32); + public readonly int MethodEnd => (int)(uint)(_versionAndMethod >> 32); } public readonly struct TargetOffsetPathLength diff --git a/src/Servers/Kestrel/Core/src/Internal/Http2/FlowControl/FlowControl.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/FlowControl/FlowControl.cs index 0521b49add..4c164d4c2f 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http2/FlowControl/FlowControl.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http2/FlowControl/FlowControl.cs @@ -15,8 +15,8 @@ internal struct FlowControl IsAborted = false; } - public int Available { get; private set; } - public bool IsAborted { get; private set; } + public int Available { readonly get; private set; } + public bool IsAborted { readonly get; private set; } public void Advance(int bytes) { diff --git a/src/Servers/Kestrel/shared/PooledStreamStack.cs b/src/Servers/Kestrel/shared/PooledStreamStack.cs index 0c9d37223f..24f3a42e00 100644 --- a/src/Servers/Kestrel/shared/PooledStreamStack.cs +++ b/src/Servers/Kestrel/shared/PooledStreamStack.cs @@ -27,7 +27,7 @@ internal struct PooledStreamStack<TValue> where TValue : class, IPooledStream _size = 0; } - public int Count => _size; + public readonly int Count => _size; public bool TryPop([NotNullWhen(true)] out TValue? result) { diff --git a/src/Shared/Buffers/BufferSegmentStack.cs b/src/Shared/Buffers/BufferSegmentStack.cs index f5fcf68f37..b0884b29e3 100644 --- a/src/Shared/Buffers/BufferSegmentStack.cs +++ b/src/Shared/Buffers/BufferSegmentStack.cs @@ -18,7 +18,7 @@ internal struct BufferSegmentStack _size = 0; } - public int Count => _size; + public readonly int Count => _size; public bool TryPop([NotNullWhen(true)] out BufferSegment? result) { diff --git a/src/Shared/CertificateGeneration/CertificateManager.cs b/src/Shared/CertificateGeneration/CertificateManager.cs index e5d6be0bae..2e44c99fd5 100644 --- a/src/Shared/CertificateGeneration/CertificateManager.cs +++ b/src/Shared/CertificateGeneration/CertificateManager.cs @@ -976,7 +976,7 @@ internal abstract class CertificateManager { } - internal struct CheckCertificateStateResult + internal readonly struct CheckCertificateStateResult { public bool Success { get; } public string? FailureMessage { get; } diff --git a/src/Shared/ServerInfrastructure/BufferWriter.cs b/src/Shared/ServerInfrastructure/BufferWriter.cs index 3e3584c138..8281949493 100644 --- a/src/Shared/ServerInfrastructure/BufferWriter.cs +++ b/src/Shared/ServerInfrastructure/BufferWriter.cs @@ -49,12 +49,12 @@ internal ref struct BufferWriter<T> where T : IBufferWriter<byte> /// <summary> /// Gets the result of the last call to <see cref="IBufferWriter{T}.GetSpan(int)"/>. /// </summary> - public Span<byte> Span => _span; + public readonly Span<byte> Span => _span; /// <summary> /// Gets the total number of bytes written with this writer. /// </summary> - public long BytesCommitted => _bytesCommitted; + public readonly long BytesCommitted => _bytesCommitted; /// <summary> /// Calls <see cref="IBufferWriter{T}.Advance(int)"/> on the underlying writer |