Add readonly modifier to readonly structs (#7169)

This commit is contained in:
James Newton-King 2019-02-01 15:04:25 +13:00 committed by GitHub
parent 25869c4690
commit 574be0d22c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 55 additions and 80 deletions

View File

@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.Components
/// <summary> /// <summary>
/// A string value that can be rendered as markup such as HTML. /// A string value that can be rendered as markup such as HTML.
/// </summary> /// </summary>
public struct MarkupString public readonly struct MarkupString
{ {
/// <summary> /// <summary>
/// Constructs an instance of <see cref="MarkupString"/>. /// Constructs an instance of <see cref="MarkupString"/>.

View File

@ -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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -318,7 +318,7 @@ namespace Microsoft.AspNetCore.JsonPatch.Internal
} }
} }
protected struct PositionInfo protected readonly struct PositionInfo
{ {
public PositionInfo(PositionType type, int index) public PositionInfo(PositionType type, int index)
{ {

View File

@ -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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.JsonPatch.Exceptions; using Microsoft.AspNetCore.JsonPatch.Exceptions;
@ -8,7 +8,7 @@ using System.Text;
namespace Microsoft.AspNetCore.JsonPatch.Internal namespace Microsoft.AspNetCore.JsonPatch.Internal
{ {
public struct ParsedPath public readonly struct ParsedPath
{ {
private static readonly string[] Empty = null; private static readonly string[] Empty = null;

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Http
/// <summary> /// <summary>
/// Provides correct handling for FragmentString value when needed to generate a URI string /// Provides correct handling for FragmentString value when needed to generate a URI string
/// </summary> /// </summary>
public struct FragmentString : IEquatable<FragmentString> public readonly struct FragmentString : IEquatable<FragmentString>
{ {
/// <summary> /// <summary>
/// Represents the empty fragment string. This field is read-only. /// Represents the empty fragment string. This field is read-only.

View File

@ -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 /// Represents the host portion of a URI can be used to construct URI's properly formatted and encoded for use in
/// HTTP headers. /// HTTP headers.
/// </summary> /// </summary>
public struct HostString : IEquatable<HostString> public readonly struct HostString : IEquatable<HostString>
{ {
private readonly string _value; private readonly string _value;

View File

@ -6,7 +6,7 @@ using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Http.Internal namespace Microsoft.AspNetCore.Http.Internal
{ {
public struct HeaderSegment : IEquatable<HeaderSegment> public readonly struct HeaderSegment : IEquatable<HeaderSegment>
{ {
private readonly StringSegment _formatting; private readonly StringSegment _formatting;
private readonly StringSegment _data; private readonly StringSegment _data;

View File

@ -8,7 +8,7 @@ using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Http.Internal namespace Microsoft.AspNetCore.Http.Internal
{ {
public struct HeaderSegmentCollection : IEnumerable<HeaderSegment>, IEquatable<HeaderSegmentCollection> public readonly struct HeaderSegmentCollection : IEnumerable<HeaderSegment>, IEquatable<HeaderSegmentCollection>
{ {
private readonly StringValues _headers; private readonly StringValues _headers;

View File

@ -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 /// Provides correct escaping for Path and PathBase values when needed to reconstruct a request or redirect URI string
/// </summary> /// </summary>
[TypeConverter(typeof(PathStringConverter))] [TypeConverter(typeof(PathStringConverter))]
public struct PathString : IEquatable<PathString> public readonly struct PathString : IEquatable<PathString>
{ {
private static readonly char[] splitChar = { '/' }; private static readonly char[] splitChar = { '/' };

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Http
/// <summary> /// <summary>
/// Provides correct handling for QueryString value when needed to reconstruct a request or redirect URI string /// Provides correct handling for QueryString value when needed to reconstruct a request or redirect URI string
/// </summary> /// </summary>
public struct QueryString : IEquatable<QueryString> public readonly struct QueryString : IEquatable<QueryString>
{ {
/// <summary> /// <summary>
/// Represents the empty query string. This field is read-only. /// Represents the empty query string. This field is read-only.

View File

@ -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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;

View File

@ -189,7 +189,7 @@ namespace Microsoft.AspNetCore.Routing
/// <summary> /// <summary>
/// A snapshot of the state of a <see cref="RouteData"/> instance. /// A snapshot of the state of a <see cref="RouteData"/> instance.
/// </summary> /// </summary>
public struct RouteDataSnapshot public readonly struct RouteDataSnapshot
{ {
private readonly RouteData _routeData; private readonly RouteData _routeData;
private readonly RouteValueDictionary _dataTokens; private readonly RouteValueDictionary _dataTokens;
@ -307,4 +307,4 @@ namespace Microsoft.AspNetCore.Routing
} }
} }
} }
} }

View File

@ -3,7 +3,7 @@
namespace Microsoft.AspNetCore.Routing.DecisionTree namespace Microsoft.AspNetCore.Routing.DecisionTree
{ {
internal struct DecisionCriterionValue internal readonly struct DecisionCriterionValue
{ {
private readonly object _value; private readonly object _value;
@ -17,4 +17,4 @@ namespace Microsoft.AspNetCore.Routing.DecisionTree
get { return _value; } get { return _value; }
} }
} }
} }

View File

@ -218,11 +218,7 @@ namespace Microsoft.AspNetCore.Routing
} while (state != ParseState.End); } while (state != ParseState.End);
return new ConstraintParseResults return new ConstraintParseResults(currentIndex, inlineConstraints);
{
CurrentIndex = currentIndex,
Constraints = inlineConstraints
};
} }
private enum ParseState private enum ParseState
@ -233,11 +229,17 @@ namespace Microsoft.AspNetCore.Routing
End End
} }
private struct ConstraintParseResults private readonly struct ConstraintParseResults
{ {
public int CurrentIndex; public readonly int CurrentIndex;
public IEnumerable<InlineConstraint> Constraints; public readonly IEnumerable<InlineConstraint> Constraints;
public ConstraintParseResults(int currentIndex, IEnumerable<InlineConstraint> constraints)
{
CurrentIndex = currentIndex;
Constraints = constraints;
}
} }
} }
} }

View File

@ -3,7 +3,7 @@
namespace Microsoft.AspNetCore.Routing.Internal namespace Microsoft.AspNetCore.Routing.Internal
{ {
public struct BufferValue public readonly struct BufferValue
{ {
public BufferValue(string value, bool requiresEncoding) public BufferValue(string value, bool requiresEncoding)
{ {

View File

@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Routing.Tree;
namespace Microsoft.AspNetCore.Routing.Internal namespace Microsoft.AspNetCore.Routing.Internal
{ {
public struct OutboundMatchResult public readonly struct OutboundMatchResult
{ {
public OutboundMatchResult(OutboundMatch match, bool isFallbackMatch) public OutboundMatchResult(OutboundMatch match, bool isFallbackMatch)
{ {
@ -17,4 +17,4 @@ namespace Microsoft.AspNetCore.Routing.Internal
public bool IsFallbackMatch { get; } public bool IsFallbackMatch { get; }
} }
} }

View File

@ -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!");
});
}
}
}

View File

@ -67,8 +67,6 @@ namespace MvcSandbox
}); });
builder.MapApplication(); builder.MapApplication();
builder.MapHealthChecks("/healthz");
}); });
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();

View File

@ -762,7 +762,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
public bool Suppressed { get; set; } public bool Suppressed { get; set; }
} }
private struct TagHelperScopeInfo private readonly struct TagHelperScopeInfo
{ {
public TagHelperScopeInfo(ViewBuffer buffer, HtmlEncoder encoder, TextWriter writer) public TagHelperScopeInfo(ViewBuffer buffer, HtmlEncoder encoder, TextWriter writer)
{ {

View File

@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public class ModelMetadataTest public class ModelMetadataTest
{ {
// IsComplexType // IsComplexType
private struct IsComplexTypeModel private readonly struct IsComplexTypeModel
{ {
} }

View File

@ -1277,13 +1277,14 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
public PointStruct Point { get; set; } public PointStruct Point { get; set; }
} }
private struct PointStruct private readonly struct PointStruct
{ {
public PointStruct(double x, double y) public PointStruct(double x, double y)
{ {
X = x; X = x;
Y = y; Y = y;
} }
public double X { get; } public double X { get; }
public double Y { get; } public double Y { get; }
} }

View File

@ -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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http 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) public Http1ParsingHandler(Http1Connection connection)
{ {

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack 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 // http://httpwg.org/specs/rfc7541.html#rfc.section.4.1
public const int RfcOverhead = 32; public const int RfcOverhead = 32;

View File

@ -3,7 +3,7 @@
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{ {
public struct Http2PeerSetting public readonly struct Http2PeerSetting
{ {
public Http2PeerSetting(Http2SettingsParameter parameter, uint value) public Http2PeerSetting(Http2SettingsParameter parameter, uint value)
{ {

View File

@ -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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -16,11 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
public override void Schedule(Action<object> action, object state) public override void Schedule(Action<object> action, object state)
{ {
var work = new Work var work = new Work(action, state);
{
Callback = action,
State = state
};
_workItems.Enqueue(work); _workItems.Enqueue(work);
@ -54,10 +50,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
} }
} }
private struct Work private readonly struct Work
{ {
public Action<object> Callback; public readonly Action<object> Callback;
public object State; public readonly object State;
public Work(Action<object> callback, object state)
{
Callback = callback;
State = state;
}
} }
} }
} }

View File

@ -8,7 +8,7 @@ using System.Runtime.CompilerServices;
namespace Microsoft.Extensions.Internal namespace Microsoft.Extensions.Internal
{ {
internal struct AwaitableInfo internal readonly struct AwaitableInfo
{ {
public Type AwaiterType { get; } public Type AwaiterType { get; }
public PropertyInfo AwaiterIsCompletedProperty { get; } public PropertyInfo AwaiterIsCompletedProperty { get; }

View File

@ -6,7 +6,7 @@ using System.Linq.Expressions;
namespace Microsoft.Extensions.Internal namespace Microsoft.Extensions.Internal
{ {
internal struct CoercedAwaitableInfo internal readonly struct CoercedAwaitableInfo
{ {
public AwaitableInfo AwaitableInfo { get; } public AwaitableInfo AwaitableInfo { get; }
public Expression CoercerExpression { get; } public Expression CoercerExpression { get; }

View File

@ -11,7 +11,7 @@ namespace Microsoft.Extensions.Internal
/// return, regardless of whether the underlying value is a System.Task, an FSharpAsync, or an /// return, regardless of whether the underlying value is a System.Task, an FSharpAsync, or an
/// application-defined custom awaitable. /// application-defined custom awaitable.
/// </summary> /// </summary>
internal struct ObjectMethodExecutorAwaitable internal readonly struct ObjectMethodExecutorAwaitable
{ {
private readonly object _customAwaitable; private readonly object _customAwaitable;
private readonly Func<object, object> _getAwaiterMethod; private readonly Func<object, object> _getAwaiterMethod;
@ -60,7 +60,7 @@ namespace Microsoft.Extensions.Internal
return new Awaiter(customAwaiter, _isCompletedMethod, _getResultMethod, _onCompletedMethod, _unsafeOnCompletedMethod); return new Awaiter(customAwaiter, _isCompletedMethod, _getResultMethod, _onCompletedMethod, _unsafeOnCompletedMethod);
} }
public struct Awaiter : ICriticalNotifyCompletion public readonly struct Awaiter : ICriticalNotifyCompletion
{ {
private readonly object _customAwaiter; private readonly object _customAwaiter;
private readonly Func<object, bool> _isCompletedMethod; private readonly Func<object, bool> _isCompletedMethod;
@ -111,4 +111,4 @@ namespace Microsoft.Extensions.Internal
} }
} }
} }
} }