readonly all the things (#1901)

This commit is contained in:
James Newton-King 2018-04-08 15:47:01 +12:00 committed by GitHub
parent a3337eb6bd
commit 0f663cadc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 34 additions and 34 deletions

View File

@ -22,10 +22,10 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
private RedisHubLifetimeManager<TestHub> _manager2;
private TestClient[] _clients;
private object[] _args;
private List<string> _excludedIds = new List<string>();
private List<string> _sendIds = new List<string>();
private List<string> _groups = new List<string>();
private List<string> _users = new List<string>();
private readonly List<string> _excludedIds = new List<string>();
private readonly List<string> _sendIds = new List<string>();
private readonly List<string> _groups = new List<string>();
private readonly List<string> _users = new List<string>();
private const int ClientCount = 20;

View File

@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
private class DummyProtocol: IHubProtocol
{
private static byte[] _fixedOutput = new byte[] { 0x68, 0x68, 0x6C, 0x6C, 0x6F };
private static readonly byte[] _fixedOutput = new byte[] { 0x68, 0x68, 0x6C, 0x6C, 0x6F };
public string Name { get; }

View File

@ -16,8 +16,8 @@ namespace ClientSample
private volatile bool _aborted;
private readonly EndPoint _endPoint;
private IDuplexPipe _application;
private SocketSender _sender;
private SocketReceiver _receiver;
private readonly SocketSender _sender;
private readonly SocketReceiver _receiver;
public TcpConnection(EndPoint endPoint)
{

View File

@ -9,9 +9,9 @@ namespace SocialWeather
{
public class FormatterResolver
{
private IServiceProvider _serviceProvider;
private readonly IServiceProvider _serviceProvider;
private Dictionary<string, Dictionary<Type, Type>> _formatters
private readonly Dictionary<string, Dictionary<Type, Type>> _formatters
= new Dictionary<string, Dictionary<Type, Type>>();
public FormatterResolver(IServiceProvider serviceProvider)

View File

@ -9,7 +9,7 @@ namespace SocialWeather.Json
{
public class JsonStreamFormatter<T> : IStreamFormatter<T>
{
private JsonSerializer _serializer = new JsonSerializer();
private readonly JsonSerializer _serializer = new JsonSerializer();
public async Task<T> ReadAsync(Stream stream)
{

View File

@ -15,12 +15,12 @@ namespace Microsoft.AspNetCore.Http.Connections.Client.Internal
private const byte ByteLF = (byte)'\n';
private const byte ByteColon = (byte)':';
private static byte[] _dataPrefix = Encoding.UTF8.GetBytes("data: ");
private static byte[] _sseLineEnding = Encoding.UTF8.GetBytes("\r\n");
private static byte[] _newLine = Encoding.UTF8.GetBytes(Environment.NewLine);
private static readonly byte[] _dataPrefix = Encoding.UTF8.GetBytes("data: ");
private static readonly byte[] _sseLineEnding = Encoding.UTF8.GetBytes("\r\n");
private static readonly byte[] _newLine = Encoding.UTF8.GetBytes(Environment.NewLine);
private InternalParseState _internalParserState = InternalParseState.ReadMessagePayload;
private List<byte[]> _data = new List<byte[]>();
private readonly List<byte[]> _data = new List<byte[]>();
public ParseResult ParseMessage(ReadOnlySequence<byte> buffer, out SequencePosition consumed, out SequencePosition examined, out byte[] message)
{

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Http.Connections
private Timer _timer;
private readonly ILogger<HttpConnectionManager> _logger;
private readonly ILogger<HttpConnectionContext> _connectionLogger;
private object _executionLock = new object();
private readonly object _executionLock = new object();
private bool _disposed;
public HttpConnectionManager(ILoggerFactory loggerFactory, IApplicationLifetime appLifetime)

View File

@ -7,9 +7,9 @@ namespace Microsoft.AspNetCore.SignalR
{
public class HubCallerClients : IHubCallerClients
{
private string _connectionId;
private IHubClients _hubClients;
private string[] _currentConnectionId;
private readonly string _connectionId;
private readonly IHubClients _hubClients;
private readonly string[] _currentConnectionId;
public HubCallerClients(IHubClients hubClients, string connectionId)
{

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.SignalR
private const string ClientModuleName = "Microsoft.AspNetCore.SignalR.TypedClientBuilder";
// There is one static instance of _builder per T
private static Lazy<Func<IClientProxy, T>> _builder = new Lazy<Func<IClientProxy, T>>(() => GenerateClientBuilder());
private static readonly Lazy<Func<IClientProxy, T>> _builder = new Lazy<Func<IClientProxy, T>>(() => GenerateClientBuilder());
public static T Build(IClientProxy proxy)
{

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.SignalR
{
internal class TypedHubClients<T> : IHubCallerClients<T>
{
private IHubCallerClients _hubClients;
private readonly IHubCallerClients _hubClients;
public TypedHubClients(IHubCallerClients dynamicContext)
{

View File

@ -579,8 +579,8 @@ namespace Microsoft.AspNetCore.SignalR.Redis
private class GroupData
{
public SemaphoreSlim Lock = new SemaphoreSlim(1, 1);
public HubConnectionStore Connections = new HubConnectionStore();
public readonly SemaphoreSlim Lock = new SemaphoreSlim(1, 1);
public readonly HubConnectionStore Connections = new HubConnectionStore();
}
private interface IRedisFeature

View File

@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
{
public class MapConnectionHandlerTests
{
private ITestOutputHelper _output;
private readonly ITestOutputHelper _output;
public MapConnectionHandlerTests(ITestOutputHelper output)
{

View File

@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
{ "ValueWithNewLines", "Also\nWorks\r\nFine" },
};
private static MessagePackObject TestHeadersSerialized = Map(
private static readonly MessagePackObject TestHeadersSerialized = Map(
("Foo", "Bar"),
("KeyWith\nNew\r\nLines", "Still Works"),
("ValueWithNewLines", "Also\nWorks\r\nFine"));
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
private static readonly MessagePackHubProtocol _hubProtocol
= new MessagePackHubProtocol();
private static MessagePackObject CustomObjectSerialized = Map(
private static readonly MessagePackObject CustomObjectSerialized = Map(
("ByteArrProp", new MessagePackObject(new byte[] { 1, 2, 3 }, isBinary: true)),
("DateTimeProp", new MessagePackObject(Timestamp.FromDateTime(new DateTime(2017, 4, 11)))),
("DoubleProp", 6.2831853071),

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
private static readonly string _exeSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty;
private static readonly string _dockerContainerName = "redisTestContainer";
private static Lazy<Docker> _instance = new Lazy<Docker>(Create);
private static readonly Lazy<Docker> _instance = new Lazy<Docker>(Create);
public static Docker Default => _instance.Value;

View File

@ -148,7 +148,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
// TestSink doesn't seem to be thread-safe :(.
private class LogSinkProvider : ILoggerProvider
{
private ConcurrentQueue<LogRecord> _logs = new ConcurrentQueue<LogRecord>();
private readonly ConcurrentQueue<LogRecord> _logs = new ConcurrentQueue<LogRecord>();
public ILogger CreateLogger(string categoryName)
{
@ -179,8 +179,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
private class LogSinkLogger : ILogger
{
private string _categoryName;
private LogSinkProvider _logSinkProvider;
private readonly string _categoryName;
private readonly LogSinkProvider _logSinkProvider;
public LogSinkLogger(string categoryName, LogSinkProvider logSinkProvider)
{

View File

@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
remove { }
}
private ISubscriber _subscriber;
private readonly ISubscriber _subscriber;
public TestConnectionMultiplexer(TestRedisServer server)
{
@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
public class TestRedisServer
{
private ConcurrentDictionary<RedisChannel, List<Action<RedisChannel, RedisValue>>> _subscriptions =
private readonly ConcurrentDictionary<RedisChannel, List<Action<RedisChannel, RedisValue>>> _subscriptions =
new ConcurrentDictionary<RedisChannel, List<Action<RedisChannel, RedisValue>>>();
public long Publish(RedisChannel channel, RedisValue message, CommandFlags flags = CommandFlags.None)

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{
internal class CancellationDisposable : IDisposable
{
private CancellationTokenSource _cts;
private readonly CancellationTokenSource _cts;
public CancellationDisposable(CancellationTokenSource cts)
{

View File

@ -473,7 +473,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
private string _prevConnectionId = null;
private IDuplexPipe _application;
private IDuplexPipe _transport;
private int availableTransports = 3;
private readonly int availableTransports = 3;
public PipeReader Input => _transport.Input;

View File

@ -498,7 +498,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
public class ConnectionLifetimeHub : Hub
{
private ConnectionLifetimeState _state;
private readonly ConnectionLifetimeState _state;
public ConnectionLifetimeHub(ConnectionLifetimeState state)
{