Skip to content

Commit

Permalink
Merge pull request #2352 from Lehonti/master
Browse files Browse the repository at this point in the history
  • Loading branch information
mbdavid authored Aug 11, 2023
2 parents d13058f + d4d3d13 commit d2ded92
Show file tree
Hide file tree
Showing 44 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion LiteDB.Shell/Utils/OptionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LiteDB.Shell
/// </summary>
internal class OptionSet
{
private Dictionary<string, OptionsParam> _options = new Dictionary<string, OptionsParam>(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, OptionsParam> _options = new Dictionary<string, OptionsParam>(StringComparer.OrdinalIgnoreCase);

/// <summary>
/// Register all extra non parameter (without -- or /)
Expand Down
6 changes: 3 additions & 3 deletions LiteDB.Stress/Test/InsertField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public enum InsertFieldType { Name, Int, Guid, Bool, Now, Binary, Date, Json }

public class InsertField
{
private Random _rnd = new Random();
private readonly Random _rnd = new Random();

#region Names

private static string[] _firstNames = new string[]
private static readonly string[] _firstNames = new string[]
{
"Blaze", "Zenia", "Malik", "Palmer", "Valentine", "Quinn", "Preston", "John", "Ferdinand", "Cassidy", "Kai", "Alma", "Cullen",
"Colorado", "Sean", "Kadeem", "Faith", "Dexter", "Olympia", "Alden", "Gloria", "Dahlia", "Melissa", "Fiona", "Oliver", "Daryl",
Expand Down Expand Up @@ -95,7 +95,7 @@ public class InsertField
"Perry", "Jason", "Levi", "Deacon", "Reese", "Arsenio", "Molly", "Cade", "Mufutau", "Cole", "Tamara", "Ann"
};

private static string[] _lastNames = new string[]
private static readonly string[] _lastNames = new string[]
{
"Hakeem", "Jena", "Donna", "Cameron", "Ramona", "Guy", "Frances", "Price", "Sydnee", "Miriam", "Quinlan", "Margaret", "Mikayla", "Chester",
"Dean", "Priscilla", "Astra", "Debra", "Kasimir", "Kane", "Amelia", "Phoebe", "Justina", "Brady", "Sybil", "Zeus", "Amethyst", "Dante",
Expand Down
2 changes: 1 addition & 1 deletion LiteDB.Stress/Test/InsertTaskItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace LiteDB.Stress
{
public class InsertTaskItem : ITestItem
{
private Random _rnd = new Random();
private readonly Random _rnd = new Random();

private ILiteCollection<BsonDocument> _collection;

Expand Down
6 changes: 3 additions & 3 deletions LiteDB.Tests/Database/IndexSortAndFilter_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class Item

#endregion

private ILiteCollection<Item> _collection;
private TempFile _tempFile;
private ILiteDatabase _database;
private readonly ILiteCollection<Item> _collection;
private readonly TempFile _tempFile;
private readonly ILiteDatabase _database;

public IndexSortAndFilterTest()
{
Expand Down
10 changes: 5 additions & 5 deletions LiteDB.Tests/Database/Storage_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace LiteDB.Tests.Database
{
public class Storage_Tests
{
private Random _rnd = new Random();
private byte[] _smallFile;
private byte[] _bigFile;
private string _smallHash;
private string _bigHash;
private readonly Random _rnd = new Random();
private readonly byte[] _smallFile;
private readonly byte[] _bigFile;
private readonly string _smallHash;
private readonly string _bigHash;

public Storage_Tests()
{
Expand Down
2 changes: 1 addition & 1 deletion LiteDB.Tests/Engine/Collation_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void Collaction_New_Database()
}
}

private string[] data = new string[]
private readonly string[] data = new string[]
{
"r6pfkr.4keQyr", "r6pfjI.31qrGW", "r6pfjy.1ryYCW", "r6pfjs.1iCqiD", "r6pfjm.2xXoUr", "r6pfj9.sYaWO", "r6pfgj.1aguPU", "r6pfgd.kKEyS",
"r6pfg7.1PD90r", "r6pffZ.1JrB8C", "r6pffU.4Exn9y", "r6pffN.atYDW", "r6pfc1.4cqgs6", "r6pfbF.1YAU7Y", "r6pfbx.463ddU", "r6pfbr.3HzECI",
Expand Down
2 changes: 1 addition & 1 deletion LiteDB.Tests/Internals/Sort_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace LiteDB.Internals
{
public class Sort_Tests
{
private IStreamFactory _factory = new StreamFactory(new MemoryStream(), null);
private readonly IStreamFactory _factory = new StreamFactory(new MemoryStream(), null);

[Fact]
public void Sort_String_Asc()
Expand Down
2 changes: 1 addition & 1 deletion LiteDB.Tests/Issues/Issue2112_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace LiteDB.Tests.Issues
{
public class Issue2112_Tests
{
private BsonMapper _mapper = new BsonMapper();
private readonly BsonMapper _mapper = new BsonMapper();

[Fact]
public void Serialize_covariant_collection_has_type()
Expand Down
2 changes: 1 addition & 1 deletion LiteDB.Tests/Mapper/CustomMappingCtor_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public ClassByte(byte myByte)
}
}

private BsonMapper _mapper = new BsonMapper();
private readonly BsonMapper _mapper = new BsonMapper();

[Fact]
public void Custom_Ctor()
Expand Down
2 changes: 1 addition & 1 deletion LiteDB.Tests/Mapper/Dictionary_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Dict
public IDictionary<DateTime, string> DateDict { get; set; } = new Dictionary<DateTime, string>();
}

private BsonMapper _mapper = new BsonMapper();
private readonly BsonMapper _mapper = new BsonMapper();

[Fact]
public void Dictionary_Map()
Expand Down
2 changes: 1 addition & 1 deletion LiteDB.Tests/Mapper/GenericMap_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class User<T, K>
public K Name { get; set; }
}

private BsonMapper _mapper = new BsonMapper();
private readonly BsonMapper _mapper = new BsonMapper();

[Fact]
public void Generic_Map()
Expand Down
2 changes: 1 addition & 1 deletion LiteDB.Tests/Mapper/LinqBsonExpression_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class Product

#endregion

private BsonMapper _mapper = new BsonMapper();
private readonly BsonMapper _mapper = new BsonMapper();

[Fact]
public void Linq_Document_Navigation()
Expand Down
2 changes: 1 addition & 1 deletion LiteDB.Tests/Mapper/LinqEval_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum PhoneType

#endregion

private BsonMapper _mapper = new BsonMapper();
private readonly BsonMapper _mapper = new BsonMapper();

[Fact]
public void Linq_Date_Eval()
Expand Down
2 changes: 1 addition & 1 deletion LiteDB.Tests/Mapper/Mapper_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace LiteDB.Tests.Mapper
{
public class Mapper_Tests
{
private BsonMapper _mapper = new BsonMapper();
private readonly BsonMapper _mapper = new BsonMapper();

[Fact]
public void ToDocument_ReturnsNull_WhenFail()
Expand Down
6 changes: 3 additions & 3 deletions LiteDB.Tests/Query/GroupBy_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace LiteDB.Tests.QueryTest
{
public class GroupBy_Tests : IDisposable
{
private Person[] local;
private readonly Person[] local;

private ILiteDatabase db;
private ILiteCollection<Person> collection;
private readonly ILiteDatabase db;
private readonly ILiteCollection<Person> collection;

public GroupBy_Tests()
{
Expand Down
4 changes: 2 additions & 2 deletions LiteDB/Client/Mapper/BsonMapper.Deserialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class BsonMapper
#region Basic direct .NET convert types

// direct bson types
private HashSet<Type> _bsonTypes = new HashSet<Type>
private readonly HashSet<Type> _bsonTypes = new HashSet<Type>
{
typeof(String),
typeof(Int32),
Expand All @@ -27,7 +27,7 @@ public partial class BsonMapper
};

// simple convert types
private HashSet<Type> _basicTypes = new HashSet<Type>
private readonly HashSet<Type> _basicTypes = new HashSet<Type>
{
typeof(Int16),
typeof(UInt16),
Expand Down
8 changes: 4 additions & 4 deletions LiteDB/Client/Mapper/BsonMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public partial class BsonMapper
/// <summary>
/// Mapping cache between Class/BsonDocument
/// </summary>
private Dictionary<Type, EntityMapper> _entities = new Dictionary<Type, EntityMapper>();
private readonly Dictionary<Type, EntityMapper> _entities = new Dictionary<Type, EntityMapper>();

/// <summary>
/// Map serializer/deserialize for custom types
/// </summary>
private ConcurrentDictionary<Type, Func<object, BsonValue>> _customSerializer = new ConcurrentDictionary<Type, Func<object, BsonValue>>();
private readonly ConcurrentDictionary<Type, Func<object, BsonValue>> _customSerializer = new ConcurrentDictionary<Type, Func<object, BsonValue>>();

private ConcurrentDictionary<Type, Func<BsonValue, object>> _customDeserializer = new ConcurrentDictionary<Type, Func<BsonValue, object>>();
private readonly ConcurrentDictionary<Type, Func<BsonValue, object>> _customDeserializer = new ConcurrentDictionary<Type, Func<BsonValue, object>>();

/// <summary>
/// Type instantiator function to support IoC
Expand Down Expand Up @@ -212,7 +212,7 @@ public BsonMapper UseCamelCase()
return this;
}

private Regex _lowerCaseDelimiter = new Regex("(?!(^[A-Z]))([A-Z])", RegexOptions.Compiled);
private readonly Regex _lowerCaseDelimiter = new Regex("(?!(^[A-Z]))([A-Z])", RegexOptions.Compiled);

/// <summary>
/// Uses lower camel case with delimiter to convert property names to field names
Expand Down
6 changes: 3 additions & 3 deletions LiteDB/Client/Mapper/EntityBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace LiteDB
/// </summary>
public class EntityBuilder<T>
{
private BsonMapper _mapper;
private EntityMapper _entity;
private ITypeNameBinder _typeNameBinder;
private readonly BsonMapper _mapper;
private readonly EntityMapper _entity;
private readonly ITypeNameBinder _typeNameBinder;

internal EntityBuilder(BsonMapper mapper, ITypeNameBinder typeNameBinder)
{
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace LiteDB
{
internal class LinqExpressionVisitor : ExpressionVisitor
{
private static Dictionary<Type, ITypeResolver> _resolver = new Dictionary<Type, ITypeResolver>
private static readonly Dictionary<Type, ITypeResolver> _resolver = new Dictionary<Type, ITypeResolver>
{
[typeof(BsonValue)] = new BsonValueResolver(),
[typeof(BsonArray)] = new BsonValueResolver(),
Expand Down
4 changes: 2 additions & 2 deletions LiteDB/Client/Mapper/Reflection/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal partial class Reflection
{
#region CreateInstance

private static Dictionary<Type, CreateObject> _cacheCtor = new Dictionary<Type, CreateObject>();
private static readonly Dictionary<Type, CreateObject> _cacheCtor = new Dictionary<Type, CreateObject>();

/// <summary>
/// Create a new instance from a Type
Expand Down Expand Up @@ -280,7 +280,7 @@ public static MemberInfo SelectMember(IEnumerable<MemberInfo> members, params Fu

#region MethodName

private static Dictionary<MethodInfo, string> _cacheName = new Dictionary<MethodInfo, string>();
private static readonly Dictionary<MethodInfo, string> _cacheName = new Dictionary<MethodInfo, string>();

/// <summary>
/// Get a friendly method name with parameter types
Expand Down
8 changes: 4 additions & 4 deletions LiteDB/Document/Expression/BsonExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ internal BsonValue ExecuteScalar(IEnumerable<BsonDocument> source, BsonDocument

#region Static method

private static ConcurrentDictionary<string, BsonExpressionEnumerableDelegate> _cacheEnumerable = new ConcurrentDictionary<string, BsonExpressionEnumerableDelegate>();
private static ConcurrentDictionary<string, BsonExpressionScalarDelegate> _cacheScalar = new ConcurrentDictionary<string, BsonExpressionScalarDelegate>();
private static readonly ConcurrentDictionary<string, BsonExpressionEnumerableDelegate> _cacheEnumerable = new ConcurrentDictionary<string, BsonExpressionEnumerableDelegate>();
private static readonly ConcurrentDictionary<string, BsonExpressionScalarDelegate> _cacheScalar = new ConcurrentDictionary<string, BsonExpressionScalarDelegate>();

/// <summary>
/// Parse string and create new instance of BsonExpression - can be cached
Expand Down Expand Up @@ -412,7 +412,7 @@ internal static void SetParameters(BsonExpression expr, BsonDocument parameters)
/// <summary>
/// Load all static methods from BsonExpressionMethods class. Use a dictionary using name + parameter count
/// </summary>
private static Dictionary<string, MethodInfo> _methods =
private static readonly Dictionary<string, MethodInfo> _methods =
typeof(BsonExpressionMethods).GetMethods(BindingFlags.Public | BindingFlags.Static)
.ToDictionary(m => m.Name.ToUpperInvariant() + "~" + m.GetParameters().Where(p => p.ParameterType != typeof(Collation)).Count());

Expand All @@ -438,7 +438,7 @@ internal static MethodInfo GetMethod(string name, int parameterCount)
/// <summary>
/// Load all static methods from BsonExpressionFunctions class. Use a dictionary using name + parameter count
/// </summary>
private static Dictionary<string, MethodInfo> _functions =
private static readonly Dictionary<string, MethodInfo> _functions =
typeof(BsonExpressionFunctions).GetMethods(BindingFlags.Public | BindingFlags.Static)
.ToDictionary(m => m.Name.ToUpperInvariant() + "~" + m.GetParameters()
.Skip(5).Count());
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Document/Expression/Methods/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static IEnumerable<BsonValue> DISTINCT(IEnumerable<BsonValue> items)
return items.Distinct();
}

private static Random _random = new Random();
private static readonly Random _random = new Random();

/// <summary>
/// Return a random int value
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Document/Json/JsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class JsonReader
{
private readonly static IFormatProvider _numberFormat = CultureInfo.InvariantCulture.NumberFormat;

private Tokenizer _tokenizer = null;
private readonly Tokenizer _tokenizer = null;

public long Position { get { return _tokenizer.Position; } }

Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Document/Json/JsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class JsonWriter
{
private readonly static IFormatProvider _numberFormat = CultureInfo.InvariantCulture.NumberFormat;

private TextWriter _writer;
private readonly TextWriter _writer;
private int _indent;
private string _spacer = "";

Expand Down
4 changes: 2 additions & 2 deletions LiteDB/Document/ObjectId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ public override string ToString()

#region Static methods

private static int _machine;
private static short _pid;
private static readonly int _machine;
private static readonly short _pid;
private static int _increment;

// static constructor
Expand Down
4 changes: 2 additions & 2 deletions LiteDB/Engine/Disk/Serializer/BufferPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace LiteDB.Engine
/// </summary>
internal class BufferPool
{
private static object _lock;
private static ArrayPool<byte> _bytePool;
private static readonly object _lock;
private static readonly ArrayPool<byte> _bytePool;

static BufferPool()
{
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Engine/Engine/Sequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class LiteEngine
/// <summary>
/// Sequence cache for collections last ID (for int/long numbers only)
/// </summary>
private ConcurrentDictionary<string, long> _sequences = new ConcurrentDictionary<string, long>(StringComparer.OrdinalIgnoreCase);
private readonly ConcurrentDictionary<string, long> _sequences = new ConcurrentDictionary<string, long>(StringComparer.OrdinalIgnoreCase);

/// <summary>
/// Get lastest value from a _id collection and plus 1 - use _sequence cache
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Engine/Engine/SystemCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace LiteDB.Engine
{
public partial class LiteEngine
{
private Dictionary<string, SystemCollection> _systemCollections = new Dictionary<string, SystemCollection>(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, SystemCollection> _systemCollections = new Dictionary<string, SystemCollection>(StringComparer.OrdinalIgnoreCase);

/// <summary>
/// Get registered system collection
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Engine/FileReader/Legacy/BsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LiteDB
/// </summary>
internal class BsonReader
{
private bool _utcDate = false;
private readonly bool _utcDate = false;

public BsonReader(bool utcDate)
{
Expand Down
4 changes: 2 additions & 2 deletions LiteDB/Engine/FileReader/Legacy/ByteReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace LiteDB
{
internal class ByteReader
{
private byte[] _buffer;
private int _length;
private readonly byte[] _buffer;
private readonly int _length;
private int _pos;

public int Position { get { return _pos; } set { _pos = value; } }
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Engine/Pages/DataPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public IEnumerable<PageAddress> GetBlocks()
/// 30% - 60% = 3 (2448 - 4895)
/// 0% - 30% = 4 (0000 - 2447)
/// </summary>
private static int[] _freePageSlots = new[]
private static readonly int[] _freePageSlots = new[]
{
(int)((PAGE_SIZE - PAGE_HEADER_SIZE) * .90), // 0
(int)((PAGE_SIZE - PAGE_HEADER_SIZE) * .75), // 1
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Engine/Query/IndexQuery/IndexEquals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace LiteDB.Engine
/// </summary>
internal class IndexEquals : Index
{
private BsonValue _value;
private readonly BsonValue _value;

public IndexEquals(string name, BsonValue value)
: base(name, Query.Ascending)
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Engine/Query/IndexQuery/IndexIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace LiteDB.Engine
/// </summary>
internal class IndexIn : Index
{
private BsonArray _values;
private readonly BsonArray _values;

public IndexIn(string name, BsonArray values, int order)
: base(name, order)
Expand Down
Loading

0 comments on commit d2ded92

Please sign in to comment.