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>
/// A string value that can be rendered as markup such as HTML.
/// </summary>
public struct MarkupString
public readonly struct MarkupString
{
/// <summary>
/// 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.
using System;
@ -318,7 +318,7 @@ namespace Microsoft.AspNetCore.JsonPatch.Internal
}
}
protected struct PositionInfo
protected readonly struct PositionInfo
{
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.
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;

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Http
/// <summary>
/// Provides correct handling for FragmentString value when needed to generate a URI string
/// </summary>
public struct FragmentString : IEquatable<FragmentString>
public readonly struct FragmentString : IEquatable<FragmentString>
{
/// <summary>
/// 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
/// HTTP headers.
/// </summary>
public struct HostString : IEquatable<HostString>
public readonly struct HostString : IEquatable<HostString>
{
private readonly string _value;

View File

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

View File

@ -8,7 +8,7 @@ using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Http.Internal
{
public struct HeaderSegmentCollection : IEnumerable<HeaderSegment>, IEquatable<HeaderSegmentCollection>
public readonly struct HeaderSegmentCollection : IEnumerable<HeaderSegment>, IEquatable<HeaderSegmentCollection>
{
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
/// </summary>
[TypeConverter(typeof(PathStringConverter))]
public struct PathString : IEquatable<PathString>
public readonly struct PathString : IEquatable<PathString>
{
private static readonly char[] splitChar = { '/' };

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Http
/// <summary>
/// Provides correct handling for QueryString value when needed to reconstruct a request or redirect URI string
/// </summary>
public struct QueryString : IEquatable<QueryString>
public readonly struct QueryString : IEquatable<QueryString>
{
/// <summary>
/// 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.
using System;

View File

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

View File

@ -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; }
}
}
}
}

View File

@ -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<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
{
public struct BufferValue
public readonly struct BufferValue
{
public BufferValue(string value, bool requiresEncoding)
{

View File

@ -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; }
}
}
}

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.MapHealthChecks("/healthz");
});
app.UseDeveloperExceptionPage();

View File

@ -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)
{

View File

@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public class ModelMetadataTest
{
// 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; }
}
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; }
}

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.
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)
{

View File

@ -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;

View File

@ -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)
{

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.
using System;
@ -16,11 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
public override void Schedule(Action<object> 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<object> Callback;
public object State;
public readonly Action<object> Callback;
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
{
internal struct AwaitableInfo
internal readonly struct AwaitableInfo
{
public Type AwaiterType { get; }
public PropertyInfo AwaiterIsCompletedProperty { get; }

View File

@ -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; }

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
/// application-defined custom awaitable.
/// </summary>
internal struct ObjectMethodExecutorAwaitable
internal readonly struct ObjectMethodExecutorAwaitable
{
private readonly object _customAwaitable;
private readonly Func<object, object> _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<object, bool> _isCompletedMethod;
@ -111,4 +111,4 @@ namespace Microsoft.Extensions.Internal
}
}
}
}
}