-Added readonly to structs

This commit is contained in:
James Newton-King
2018-01-31 10:32:50 +13:00
parent 4e47aa8e9a
commit e370fc2e3a
8 changed files with 13 additions and 11 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ namespace Newtonsoft.Json.Linq
/// Represents a collection of <see cref="JToken"/> objects. /// Represents a collection of <see cref="JToken"/> objects.
/// </summary> /// </summary>
/// <typeparam name="T">The type of token.</typeparam> /// <typeparam name="T">The type of token.</typeparam>
public struct JEnumerable<T> : IJEnumerable<T>, IEquatable<JEnumerable<T>> where T : JToken public readonly struct JEnumerable<T> : IJEnumerable<T>, IEquatable<JEnumerable<T>> where T : JToken
{ {
/// <summary> /// <summary>
/// An empty collection of <see cref="JToken"/> objects. /// An empty collection of <see cref="JToken"/> objects.
+4 -2
View File
@@ -33,6 +33,8 @@ namespace Newtonsoft.Json.Linq.JsonPath
{ {
internal class JPath internal class JPath
{ {
private static readonly char[] FloatCharacters = new[] {'.', 'E', 'e'};
private readonly string _expression; private readonly string _expression;
public List<PathFilter> Filters { get; } public List<PathFilter> Filters { get; }
@@ -601,7 +603,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
{ {
string numberText = sb.ToString(); string numberText = sb.ToString();
if (numberText.IndexOfAny(new[] { '.', 'E', 'e' }) != -1) if (numberText.IndexOfAny(FloatCharacters) != -1)
{ {
bool result = double.TryParse(numberText, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out var d); bool result = double.TryParse(numberText, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out var d);
value = d; value = d;
@@ -688,7 +690,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
resolvedChar = currentChar; resolvedChar = currentChar;
break; break;
default: default:
throw new JsonException(@"Unknown escape character: \" + _expression[_currentIndex]); throw new JsonException(@"Unknown escape character: \" + currentChar);
} }
sb.Append(resolvedChar); sb.Append(resolvedChar);
@@ -30,7 +30,7 @@ using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Serialization namespace Newtonsoft.Json.Serialization
{ {
internal struct ResolverContractKey : IEquatable<ResolverContractKey> internal readonly struct ResolverContractKey : IEquatable<ResolverContractKey>
{ {
private readonly Type _resolverType; private readonly Type _resolverType;
private readonly Type _contractType; private readonly Type _contractType;
@@ -248,7 +248,7 @@ namespace Newtonsoft.Json.Utilities
#endif #endif
} }
internal struct TypeConvertKey : IEquatable<TypeConvertKey> internal readonly struct TypeConvertKey : IEquatable<TypeConvertKey>
{ {
public Type InitialType { get; } public Type InitialType { get; }
@@ -482,7 +482,7 @@ namespace Newtonsoft.Json.Utilities
} }
} }
private struct DictionaryEnumerator<TEnumeratorKey, TEnumeratorValue> : IDictionaryEnumerator private readonly struct DictionaryEnumerator<TEnumeratorKey, TEnumeratorValue> : IDictionaryEnumerator
{ {
private readonly IEnumerator<KeyValuePair<TEnumeratorKey, TEnumeratorValue>> _e; private readonly IEnumerator<KeyValuePair<TEnumeratorKey, TEnumeratorValue>> _e;
+3 -3
View File
@@ -2991,10 +2991,10 @@ namespace Newtonsoft.Json.Utilities.LinqBridge
} }
[Serializable] [Serializable]
internal struct Tuple<TFirst, TSecond> : IEquatable<Tuple<TFirst, TSecond>> internal readonly struct Tuple<TFirst, TSecond> : IEquatable<Tuple<TFirst, TSecond>>
{ {
public TFirst First { get; private set; } public TFirst First { get; }
public TSecond Second { get; private set; } public TSecond Second { get; }
public Tuple(TFirst first, TSecond second) public Tuple(TFirst first, TSecond second)
: this() : this()
@@ -1109,7 +1109,7 @@ namespace Newtonsoft.Json.Utilities
} }
} }
internal struct TypeNameKey : IEquatable<TypeNameKey> internal readonly struct TypeNameKey : IEquatable<TypeNameKey>
{ {
internal readonly string AssemblyName; internal readonly string AssemblyName;
internal readonly string TypeName; internal readonly string TypeName;
@@ -27,7 +27,7 @@ using System;
namespace Newtonsoft.Json.Utilities namespace Newtonsoft.Json.Utilities
{ {
internal struct StringReference internal readonly struct StringReference
{ {
private readonly char[] _chars; private readonly char[] _chars;
private readonly int _startIndex; private readonly int _startIndex;