diff --git a/src/Components/Components/src/MarkupString.cs b/src/Components/Components/src/MarkupString.cs index fff1baafde..c0f9c8af0a 100644 --- a/src/Components/Components/src/MarkupString.cs +++ b/src/Components/Components/src/MarkupString.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.Components /// /// A string value that can be rendered as markup such as HTML. /// - public struct MarkupString + public readonly struct MarkupString { /// /// Constructs an instance of . diff --git a/src/Features/JsonPatch/src/Internal/ListAdapter.cs b/src/Features/JsonPatch/src/Internal/ListAdapter.cs index 597f7b9f5f..18b4acf217 100644 --- a/src/Features/JsonPatch/src/Internal/ListAdapter.cs +++ b/src/Features/JsonPatch/src/Internal/ListAdapter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -318,7 +318,7 @@ namespace Microsoft.AspNetCore.JsonPatch.Internal } } - protected struct PositionInfo + protected readonly struct PositionInfo { public PositionInfo(PositionType type, int index) { diff --git a/src/Features/JsonPatch/src/Internal/ParsedPath.cs b/src/Features/JsonPatch/src/Internal/ParsedPath.cs index 8d0e69aa4d..bff5fd9188 100644 --- a/src/Features/JsonPatch/src/Internal/ParsedPath.cs +++ b/src/Features/JsonPatch/src/Internal/ParsedPath.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.JsonPatch.Exceptions; @@ -8,7 +8,7 @@ using System.Text; namespace Microsoft.AspNetCore.JsonPatch.Internal { - public struct ParsedPath + public readonly struct ParsedPath { private static readonly string[] Empty = null; diff --git a/src/Http/Http.Abstractions/src/FragmentString.cs b/src/Http/Http.Abstractions/src/FragmentString.cs index c1cb306149..fbe936ce89 100644 --- a/src/Http/Http.Abstractions/src/FragmentString.cs +++ b/src/Http/Http.Abstractions/src/FragmentString.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Http /// /// Provides correct handling for FragmentString value when needed to generate a URI string /// - public struct FragmentString : IEquatable + public readonly struct FragmentString : IEquatable { /// /// Represents the empty fragment string. This field is read-only. diff --git a/src/Http/Http.Abstractions/src/HostString.cs b/src/Http/Http.Abstractions/src/HostString.cs index 7851659be0..5b83251ca3 100644 --- a/src/Http/Http.Abstractions/src/HostString.cs +++ b/src/Http/Http.Abstractions/src/HostString.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Http /// Represents the host portion of a URI can be used to construct URI's properly formatted and encoded for use in /// HTTP headers. /// - public struct HostString : IEquatable + public readonly struct HostString : IEquatable { private readonly string _value; diff --git a/src/Http/Http.Abstractions/src/Internal/HeaderSegment.cs b/src/Http/Http.Abstractions/src/Internal/HeaderSegment.cs index eed9d80f88..d2a64a53ac 100644 --- a/src/Http/Http.Abstractions/src/Internal/HeaderSegment.cs +++ b/src/Http/Http.Abstractions/src/Internal/HeaderSegment.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Http.Internal { - public struct HeaderSegment : IEquatable + public readonly struct HeaderSegment : IEquatable { private readonly StringSegment _formatting; private readonly StringSegment _data; diff --git a/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs b/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs index 40c40a8eb3..12e241eded 100644 --- a/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs +++ b/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Http.Internal { - public struct HeaderSegmentCollection : IEnumerable, IEquatable + public readonly struct HeaderSegmentCollection : IEnumerable, IEquatable { private readonly StringValues _headers; diff --git a/src/Http/Http.Abstractions/src/PathString.cs b/src/Http/Http.Abstractions/src/PathString.cs index b7f121a039..702307db8f 100644 --- a/src/Http/Http.Abstractions/src/PathString.cs +++ b/src/Http/Http.Abstractions/src/PathString.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Http /// Provides correct escaping for Path and PathBase values when needed to reconstruct a request or redirect URI string /// [TypeConverter(typeof(PathStringConverter))] - public struct PathString : IEquatable + public readonly struct PathString : IEquatable { private static readonly char[] splitChar = { '/' }; diff --git a/src/Http/Http.Abstractions/src/QueryString.cs b/src/Http/Http.Abstractions/src/QueryString.cs index 772df8dfd9..64296e6bee 100644 --- a/src/Http/Http.Abstractions/src/QueryString.cs +++ b/src/Http/Http.Abstractions/src/QueryString.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Http /// /// Provides correct handling for QueryString value when needed to reconstruct a request or redirect URI string /// - public struct QueryString : IEquatable + public readonly struct QueryString : IEquatable { /// /// Represents the empty query string. This field is read-only. diff --git a/src/Http/Http.Abstractions/src/Routing/EndpointMetadataCollection.cs b/src/Http/Http.Abstractions/src/Routing/EndpointMetadataCollection.cs index a792fff295..1f3705da77 100644 --- a/src/Http/Http.Abstractions/src/Routing/EndpointMetadataCollection.cs +++ b/src/Http/Http.Abstractions/src/Routing/EndpointMetadataCollection.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Http/Routing.Abstractions/src/RouteData.cs b/src/Http/Routing.Abstractions/src/RouteData.cs index 858c3a67f4..d2d0cd8693 100644 --- a/src/Http/Routing.Abstractions/src/RouteData.cs +++ b/src/Http/Routing.Abstractions/src/RouteData.cs @@ -189,7 +189,7 @@ namespace Microsoft.AspNetCore.Routing /// /// A snapshot of the state of a instance. /// - public struct RouteDataSnapshot + public readonly struct RouteDataSnapshot { private readonly RouteData _routeData; private readonly RouteValueDictionary _dataTokens; @@ -307,4 +307,4 @@ namespace Microsoft.AspNetCore.Routing } } } -} \ No newline at end of file +} diff --git a/src/Http/Routing/src/DecisionTree/DecisionCriterionValue.cs b/src/Http/Routing/src/DecisionTree/DecisionCriterionValue.cs index e5ed7a69f8..5bc9eaa159 100644 --- a/src/Http/Routing/src/DecisionTree/DecisionCriterionValue.cs +++ b/src/Http/Routing/src/DecisionTree/DecisionCriterionValue.cs @@ -3,7 +3,7 @@ namespace Microsoft.AspNetCore.Routing.DecisionTree { - internal struct DecisionCriterionValue + internal readonly struct DecisionCriterionValue { private readonly object _value; @@ -17,4 +17,4 @@ namespace Microsoft.AspNetCore.Routing.DecisionTree get { return _value; } } } -} \ No newline at end of file +} diff --git a/src/Http/Routing/src/InlineRouteParameterParser.cs b/src/Http/Routing/src/InlineRouteParameterParser.cs index 78131eba97..33c70558f2 100644 --- a/src/Http/Routing/src/InlineRouteParameterParser.cs +++ b/src/Http/Routing/src/InlineRouteParameterParser.cs @@ -218,11 +218,7 @@ namespace Microsoft.AspNetCore.Routing } while (state != ParseState.End); - return new ConstraintParseResults - { - CurrentIndex = currentIndex, - Constraints = inlineConstraints - }; + return new ConstraintParseResults(currentIndex, inlineConstraints); } private enum ParseState @@ -233,11 +229,17 @@ namespace Microsoft.AspNetCore.Routing End } - private struct ConstraintParseResults + private readonly struct ConstraintParseResults { - public int CurrentIndex; + public readonly int CurrentIndex; - public IEnumerable Constraints; + public readonly IEnumerable Constraints; + + public ConstraintParseResults(int currentIndex, IEnumerable constraints) + { + CurrentIndex = currentIndex; + Constraints = constraints; + } } } -} \ No newline at end of file +} diff --git a/src/Http/Routing/src/Internal/BufferValue.cs b/src/Http/Routing/src/Internal/BufferValue.cs index 578c396b4d..f71617038d 100644 --- a/src/Http/Routing/src/Internal/BufferValue.cs +++ b/src/Http/Routing/src/Internal/BufferValue.cs @@ -3,7 +3,7 @@ namespace Microsoft.AspNetCore.Routing.Internal { - public struct BufferValue + public readonly struct BufferValue { public BufferValue(string value, bool requiresEncoding) { diff --git a/src/Http/Routing/src/Internal/OutboundMatchResult.cs b/src/Http/Routing/src/Internal/OutboundMatchResult.cs index aee505f572..1b221013ba 100644 --- a/src/Http/Routing/src/Internal/OutboundMatchResult.cs +++ b/src/Http/Routing/src/Internal/OutboundMatchResult.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Routing.Tree; namespace Microsoft.AspNetCore.Routing.Internal { - public struct OutboundMatchResult + public readonly struct OutboundMatchResult { public OutboundMatchResult(OutboundMatch match, bool isFallbackMatch) { @@ -17,4 +17,4 @@ namespace Microsoft.AspNetCore.Routing.Internal public bool IsFallbackMatch { get; } } -} \ No newline at end of file +} diff --git a/src/Mvc/samples/MvcSandbox/HealthChecks/HealthChecksEndpointRouteBuilderExtensions.cs b/src/Mvc/samples/MvcSandbox/HealthChecks/HealthChecksEndpointRouteBuilderExtensions.cs deleted file mode 100644 index b89acdd2b4..0000000000 --- a/src/Mvc/samples/MvcSandbox/HealthChecks/HealthChecksEndpointRouteBuilderExtensions.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Routing; - -namespace Microsoft.AspNetCore.Builder -{ - public static class HealthChecksEndpointRouteBuilderExtensions - { - private static readonly Random _random = new Random(); - - public static IEndpointConventionBuilder MapHealthChecks(this IEndpointRouteBuilder builder, string pattern) - { - return builder.MapGet( - pattern, - async httpContext => - { - await httpContext.Response.WriteAsync(_random.Next() % 2 == 0 ? "Up!" : "Down!"); - }); - } - } -} diff --git a/src/Mvc/samples/MvcSandbox/Startup.cs b/src/Mvc/samples/MvcSandbox/Startup.cs index c7d8120ead..d6c039de1a 100644 --- a/src/Mvc/samples/MvcSandbox/Startup.cs +++ b/src/Mvc/samples/MvcSandbox/Startup.cs @@ -67,8 +67,6 @@ namespace MvcSandbox }); builder.MapApplication(); - - builder.MapHealthChecks("/healthz"); }); app.UseDeveloperExceptionPage(); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs index 8f2a98defa..f8277dca22 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs @@ -762,7 +762,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor public bool Suppressed { get; set; } } - private struct TagHelperScopeInfo + private readonly struct TagHelperScopeInfo { public TagHelperScopeInfo(ViewBuffer buffer, HtmlEncoder encoder, TextWriter writer) { diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Abstractions.Test/ModelBinding/ModelMetadataTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Abstractions.Test/ModelBinding/ModelMetadataTest.cs index b637350e3f..e72dea57e4 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Abstractions.Test/ModelBinding/ModelMetadataTest.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Abstractions.Test/ModelBinding/ModelMetadataTest.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding public class ModelMetadataTest { // IsComplexType - private struct IsComplexTypeModel + private readonly struct IsComplexTypeModel { } diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ComplexTypeModelBinderTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ComplexTypeModelBinderTest.cs index 8488a08dc2..8774ba896f 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ComplexTypeModelBinderTest.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ComplexTypeModelBinderTest.cs @@ -1277,13 +1277,14 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders public PointStruct Point { get; set; } } - private struct PointStruct + private readonly struct PointStruct { public PointStruct(double x, double y) { X = x; Y = y; } + public double X { get; } public double Y { get; } } diff --git a/src/Servers/Kestrel/Core/src/Internal/Http/Http1ParsingHandler.cs b/src/Servers/Kestrel/Core/src/Internal/Http/Http1ParsingHandler.cs index e4385351db..6c2099eade 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http/Http1ParsingHandler.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http/Http1ParsingHandler.cs @@ -1,13 +1,13 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { - public struct Http1ParsingHandler : IHttpRequestLineHandler, IHttpHeadersHandler + public readonly struct Http1ParsingHandler : IHttpRequestLineHandler, IHttpHeadersHandler { - public Http1Connection Connection; + public readonly Http1Connection Connection; public Http1ParsingHandler(Http1Connection connection) { diff --git a/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HeaderField.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HeaderField.cs index fd224f4e52..892a617df9 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HeaderField.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http2/HPack/HeaderField.cs @@ -5,7 +5,7 @@ using System; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack { - public struct HeaderField + public readonly struct HeaderField { // http://httpwg.org/specs/rfc7541.html#rfc.section.4.1 public const int RfcOverhead = 32; diff --git a/src/Servers/Kestrel/Core/src/Internal/Http2/Http2PeerSetting.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2PeerSetting.cs index f21b3ca929..90cfd223b2 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http2/Http2PeerSetting.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2PeerSetting.cs @@ -3,7 +3,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { - public struct Http2PeerSetting + public readonly struct Http2PeerSetting { public Http2PeerSetting(Http2SettingsParameter parameter, uint value) { diff --git a/src/Servers/Kestrel/Transport.Sockets/src/Internal/IOQueue.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/IOQueue.cs index e0ae0f4dfd..b187ad7e30 100644 --- a/src/Servers/Kestrel/Transport.Sockets/src/Internal/IOQueue.cs +++ b/src/Servers/Kestrel/Transport.Sockets/src/Internal/IOQueue.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -16,11 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal public override void Schedule(Action action, object state) { - var work = new Work - { - Callback = action, - State = state - }; + var work = new Work(action, state); _workItems.Enqueue(work); @@ -54,10 +50,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal } } - private struct Work + private readonly struct Work { - public Action Callback; - public object State; + public readonly Action Callback; + public readonly object State; + + public Work(Action callback, object state) + { + Callback = callback; + State = state; + } } } } diff --git a/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs b/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs index 431b83a6e5..d53c986fd2 100644 --- a/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs +++ b/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs @@ -8,7 +8,7 @@ using System.Runtime.CompilerServices; namespace Microsoft.Extensions.Internal { - internal struct AwaitableInfo + internal readonly struct AwaitableInfo { public Type AwaiterType { get; } public PropertyInfo AwaiterIsCompletedProperty { get; } diff --git a/src/Shared/ObjectMethodExecutor/CoercedAwaitableInfo.cs b/src/Shared/ObjectMethodExecutor/CoercedAwaitableInfo.cs index 4e48ef09a1..11bf32f7bc 100644 --- a/src/Shared/ObjectMethodExecutor/CoercedAwaitableInfo.cs +++ b/src/Shared/ObjectMethodExecutor/CoercedAwaitableInfo.cs @@ -6,7 +6,7 @@ using System.Linq.Expressions; namespace Microsoft.Extensions.Internal { - internal struct CoercedAwaitableInfo + internal readonly struct CoercedAwaitableInfo { public AwaitableInfo AwaitableInfo { get; } public Expression CoercerExpression { get; } diff --git a/src/Shared/ObjectMethodExecutor/ObjectMethodExecutorAwaitable.cs b/src/Shared/ObjectMethodExecutor/ObjectMethodExecutorAwaitable.cs index 7509b86b2b..02ffd7c4ce 100644 --- a/src/Shared/ObjectMethodExecutor/ObjectMethodExecutorAwaitable.cs +++ b/src/Shared/ObjectMethodExecutor/ObjectMethodExecutorAwaitable.cs @@ -11,7 +11,7 @@ namespace Microsoft.Extensions.Internal /// return, regardless of whether the underlying value is a System.Task, an FSharpAsync, or an /// application-defined custom awaitable. /// - internal struct ObjectMethodExecutorAwaitable + internal readonly struct ObjectMethodExecutorAwaitable { private readonly object _customAwaitable; private readonly Func _getAwaiterMethod; @@ -60,7 +60,7 @@ namespace Microsoft.Extensions.Internal return new Awaiter(customAwaiter, _isCompletedMethod, _getResultMethod, _onCompletedMethod, _unsafeOnCompletedMethod); } - public struct Awaiter : ICriticalNotifyCompletion + public readonly struct Awaiter : ICriticalNotifyCompletion { private readonly object _customAwaiter; private readonly Func _isCompletedMethod; @@ -111,4 +111,4 @@ namespace Microsoft.Extensions.Internal } } } -} \ No newline at end of file +}