From e30b2ab4aa0e465c9da8bc89024436db68cf096c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C4=B5=20=CE=9D=CE=B9=CE=93=CE=9E=CE=97=CE=9B=CF=88=CE=9A?= Date: Sat, 7 Oct 2023 12:49:35 +0530 Subject: [PATCH] code cleanup --- Benchmark/Benchmarks/BenchBase.cs | 2 +- Benchmark/Benchmarks/Create.cs | 2 +- Benchmark/Benchmarks/FileStorageRead.cs | 6 +- Benchmark/Benchmarks/FileStorageWrite.cs | 2 +- Benchmark/Benchmarks/Find.cs | 20 +- Benchmark/Benchmarks/Relationships.cs | 4 +- Benchmark/Benchmarks/Save.cs | 4 +- Benchmark/Benchmarks/Update.cs | 6 +- Benchmark/Benchmarks/Watcher.cs | 2 +- Benchmark/Program.cs | 2 +- MongoDB.Entities/Builders/Distinct.cs | 12 +- MongoDB.Entities/Builders/Find.cs | 14 +- MongoDB.Entities/Builders/Index.cs | 6 +- MongoDB.Entities/Builders/PagedSearch.cs | 20 +- MongoDB.Entities/Builders/Replace.cs | 20 +- MongoDB.Entities/Builders/Update.cs | 20 +- MongoDB.Entities/Builders/UpdateAndGet.cs | 16 +- .../Core/Attributes/IdAttributes.cs | 4 +- MongoDB.Entities/Core/Cache.cs | 10 +- MongoDB.Entities/Core/Entities/FileEntity.cs | 22 +- .../Core/Entities/SequenceCounter.cs | 2 +- .../Core/IgnoreManyPropsConvention.cs | 2 +- MongoDB.Entities/Core/Logic.cs | 2 +- MongoDB.Entities/Core/Serializers/Date.cs | 10 +- .../Core/Serializers/FuzzyString.cs | 4 +- MongoDB.Entities/Core/Template.cs | 18 +- MongoDB.Entities/Core/Transaction.cs | 2 +- MongoDB.Entities/Core/TypeMap.cs | 6 +- .../Core/Utilities/DoubleMetaphone.cs | 196 +++++++++--------- .../Core/Utilities/LevenshteinDistance.cs | 6 +- MongoDB.Entities/Core/Utilities/Prop.cs | 14 +- MongoDB.Entities/Core/Watcher.cs | 14 +- MongoDB.Entities/DB/DB.Delete.cs | 8 +- MongoDB.Entities/DB/DB.Migrate.cs | 4 +- MongoDB.Entities/DB/DB.Save.cs | 10 +- MongoDB.Entities/DB/DB.cs | 4 +- .../DBContext/DBContext.Pipeline.cs | 2 +- MongoDB.Entities/DBContext/DBContext.Save.cs | 4 +- MongoDB.Entities/DBContext/DBContext.cs | 10 +- MongoDB.Entities/Extensions/Entity.cs | 4 +- MongoDB.Entities/Relationships/Many.Fluent.cs | 2 +- MongoDB.Entities/Relationships/Many.cs | 12 +- MongoDB.Entities/Relationships/One.cs | 2 +- Tests/EntityIdTests/TestCounting.cs | 4 +- Tests/EntityIdTests/TestMultiDb.cs | 2 +- Tests/EntityIdTests/TestPagedSearch.cs | 4 +- Tests/EntityIdTests/TestSaving.cs | 2 +- Tests/Int64Tests/TestCounting.cs | 4 +- Tests/Int64Tests/TestMultiDb.cs | 2 +- Tests/Int64Tests/TestPagedSearch.cs | 4 +- Tests/Int64Tests/TestSaving.cs | 2 +- Tests/ObjectIdTests/TestCounting.cs | 4 +- Tests/ObjectIdTests/TestMultiDb.cs | 2 +- Tests/ObjectIdTests/TestPagedSearch.cs | 4 +- Tests/ObjectIdTests/TestSaving.cs | 2 +- Tests/TestFileEntity.cs | 2 +- Tests/UuidTests/TestCounting.cs | 4 +- Tests/UuidTests/TestMultiDb.cs | 2 +- Tests/UuidTests/TestPagedSearch.cs | 4 +- Tests/UuidTests/TestSaving.cs | 2 +- 60 files changed, 291 insertions(+), 291 deletions(-) diff --git a/Benchmark/Benchmarks/BenchBase.cs b/Benchmark/Benchmarks/BenchBase.cs index c5d20db94..500c33473 100644 --- a/Benchmark/Benchmarks/BenchBase.cs +++ b/Benchmark/Benchmarks/BenchBase.cs @@ -7,7 +7,7 @@ namespace Benchmark; public abstract class BenchBase { - private const string DBName = "mongodb-entities-benchmark"; + const string DBName = "mongodb-entities-benchmark"; protected static IMongoCollection AuthorCollection { get; } protected static IMongoCollection BookCollection { get; } protected static IMongoDatabase Database { get; } diff --git a/Benchmark/Benchmarks/Create.cs b/Benchmark/Benchmarks/Create.cs index f24a6b724..15054861b 100644 --- a/Benchmark/Benchmarks/Create.cs +++ b/Benchmark/Benchmarks/Create.cs @@ -38,7 +38,7 @@ public override Task Official_Driver() [MemoryDiagnoser] public class CreateBulk : BenchBase { - private readonly List list = new(1000); + readonly List list = new(1000); public CreateBulk() { diff --git a/Benchmark/Benchmarks/FileStorageRead.cs b/Benchmark/Benchmarks/FileStorageRead.cs index 31eed79e7..ba3908609 100644 --- a/Benchmark/Benchmarks/FileStorageRead.cs +++ b/Benchmark/Benchmarks/FileStorageRead.cs @@ -10,10 +10,10 @@ namespace Benchmark; [MemoryDiagnoser] public partial class FileStorageRead : BenchBase { - private static readonly MemoryStream memStream = new(new byte[32 * 1024 * 1024]); + static readonly MemoryStream memStream = new(new byte[32 * 1024 * 1024]); - private readonly string fEntityID; - private readonly ObjectId gridFSId; + readonly string fEntityID; + readonly ObjectId gridFSId; public FileStorageRead() { diff --git a/Benchmark/Benchmarks/FileStorageWrite.cs b/Benchmark/Benchmarks/FileStorageWrite.cs index 7cdfa3e8d..c218a7852 100644 --- a/Benchmark/Benchmarks/FileStorageWrite.cs +++ b/Benchmark/Benchmarks/FileStorageWrite.cs @@ -9,7 +9,7 @@ namespace Benchmark; [MemoryDiagnoser] public class FileStorageWrite : BenchBase { - private static readonly MemoryStream memStream = new(new byte[32 * 1024 * 1024]); + static readonly MemoryStream memStream = new(new byte[32 * 1024 * 1024]); [Benchmark] public override async Task MongoDB_Entities() diff --git a/Benchmark/Benchmarks/Find.cs b/Benchmark/Benchmarks/Find.cs index 6ce229c20..48b60aaa9 100644 --- a/Benchmark/Benchmarks/Find.cs +++ b/Benchmark/Benchmarks/Find.cs @@ -10,8 +10,8 @@ namespace Benchmark; [MemoryDiagnoser] public class FindOne : BenchBase { - private readonly List list = new(1000); - private readonly string guid = Guid.NewGuid().ToString(); + readonly List list = new(1000); + readonly string guid = Guid.NewGuid().ToString(); public FindOne() { @@ -52,8 +52,8 @@ public override async Task Official_Driver() [MemoryDiagnoser] public class Find100 : BenchBase { - private readonly List list = new(1000); - private readonly string guid = Guid.NewGuid().ToString(); + readonly List list = new(1000); + readonly string guid = Guid.NewGuid().ToString(); public Find100() { @@ -94,8 +94,8 @@ public override async Task Official_Driver() [MemoryDiagnoser] public class FindFirst : BenchBase { - private readonly List list = new(1000); - private readonly string guid = Guid.NewGuid().ToString(); + readonly List list = new(1000); + readonly string guid = Guid.NewGuid().ToString(); public FindFirst() { @@ -136,8 +136,8 @@ public override async Task Official_Driver() [MemoryDiagnoser] public class FindAny : BenchBase { - private readonly List list = new(1000); - private readonly string guid = Guid.NewGuid().ToString(); + readonly List list = new(1000); + readonly string guid = Guid.NewGuid().ToString(); public FindAny() { @@ -178,8 +178,8 @@ public override async Task Official_Driver() [MemoryDiagnoser] public class FindSingle : BenchBase { - private readonly List list = new(1000); - private readonly string guid = Guid.NewGuid().ToString(); + readonly List list = new(1000); + readonly string guid = Guid.NewGuid().ToString(); public FindSingle() { diff --git a/Benchmark/Benchmarks/Relationships.cs b/Benchmark/Benchmarks/Relationships.cs index 3ef9c0b72..9df42c8d0 100644 --- a/Benchmark/Benchmarks/Relationships.cs +++ b/Benchmark/Benchmarks/Relationships.cs @@ -10,8 +10,8 @@ namespace Benchmark; [MemoryDiagnoser] public class Relationships : BenchBase { - private const string bookTitle = "BOOKTITLE"; - private const string authorName = "AUTHORNAME"; + const string bookTitle = "BOOKTITLE"; + const string authorName = "AUTHORNAME"; public Relationships() { diff --git a/Benchmark/Benchmarks/Save.cs b/Benchmark/Benchmarks/Save.cs index 976658277..a37184725 100644 --- a/Benchmark/Benchmarks/Save.cs +++ b/Benchmark/Benchmarks/Save.cs @@ -9,7 +9,7 @@ namespace Benchmark; [MemoryDiagnoser] public class SavePartialVsUpdate : BenchBase { - private readonly Author author; + readonly Author author; public SavePartialVsUpdate() { @@ -57,7 +57,7 @@ public override Task Official_Driver() [MemoryDiagnoser] public class DBContextVsStaticSave : BenchBase { - private readonly Author author; + readonly Author author; public DBContextVsStaticSave() { diff --git a/Benchmark/Benchmarks/Update.cs b/Benchmark/Benchmarks/Update.cs index edf083525..0ce642bae 100644 --- a/Benchmark/Benchmarks/Update.cs +++ b/Benchmark/Benchmarks/Update.cs @@ -11,7 +11,7 @@ namespace Benchmark; [MemoryDiagnoser] public class UpdateOne : BenchBase { - private readonly string id = ObjectId.GenerateNewId().ToString(); + readonly string id = ObjectId.GenerateNewId().ToString(); public UpdateOne() { @@ -39,8 +39,8 @@ public override Task Official_Driver() [MemoryDiagnoser] public class Update100 : BenchBase { - private readonly List list = new(1000); - private readonly string guid = Guid.NewGuid().ToString(); + readonly List list = new(1000); + readonly string guid = Guid.NewGuid().ToString(); public Update100() { diff --git a/Benchmark/Benchmarks/Watcher.cs b/Benchmark/Benchmarks/Watcher.cs index 648fc83b0..cc4f7d5ba 100644 --- a/Benchmark/Benchmarks/Watcher.cs +++ b/Benchmark/Benchmarks/Watcher.cs @@ -63,7 +63,7 @@ public override async Task Official_Driver() cts.Dispose(); } - private Task InsertAnEntity() + Task InsertAnEntity() { return new Book { Title = "book name" }.SaveAsync(); } diff --git a/Benchmark/Program.cs b/Benchmark/Program.cs index 9995e17a1..61a0fd4f6 100644 --- a/Benchmark/Program.cs +++ b/Benchmark/Program.cs @@ -4,7 +4,7 @@ namespace Benchmark; public static class Program { - private static void Main() + static void Main() { BenchmarkRunner.Run(typeof(Program).Assembly); } diff --git a/MongoDB.Entities/Builders/Distinct.cs b/MongoDB.Entities/Builders/Distinct.cs index 1b960057b..b466236bc 100644 --- a/MongoDB.Entities/Builders/Distinct.cs +++ b/MongoDB.Entities/Builders/Distinct.cs @@ -14,12 +14,12 @@ namespace MongoDB.Entities; /// The type of the property of the entity you'd like to get unique values for public class Distinct where T : IEntity { - private FieldDefinition? field; - private FilterDefinition filter = Builders.Filter.Empty; - private readonly DistinctOptions options = new(); - private readonly IClientSessionHandle? session; - private readonly Dictionary? globalFilters; - private bool ignoreGlobalFilters; + FieldDefinition? field; + FilterDefinition filter = Builders.Filter.Empty; + readonly DistinctOptions options = new(); + readonly IClientSessionHandle? session; + readonly Dictionary? globalFilters; + bool ignoreGlobalFilters; internal Distinct(IClientSessionHandle? session, Dictionary? globalFilters) { diff --git a/MongoDB.Entities/Builders/Find.cs b/MongoDB.Entities/Builders/Find.cs index 1edab58ae..39d4be059 100644 --- a/MongoDB.Entities/Builders/Find.cs +++ b/MongoDB.Entities/Builders/Find.cs @@ -30,12 +30,12 @@ internal Find(IClientSessionHandle? session, DictionaryThe type you'd like to project the results to. public class Find where T : IEntity { - private FilterDefinition filter = Builders.Filter.Empty; - private readonly List> sorts = new(); - private readonly FindOptions options = new(); - private readonly IClientSessionHandle? session; - private readonly Dictionary? globalFilters; - private bool ignoreGlobalFilters; + FilterDefinition filter = Builders.Filter.Empty; + readonly List> sorts = new(); + readonly FindOptions options = new(); + readonly IClientSessionHandle? session; + readonly Dictionary? globalFilters; + bool ignoreGlobalFilters; internal Find(IClientSessionHandle? session, Dictionary? globalFilters) { @@ -430,7 +430,7 @@ public Task> ExecuteCursorAsync(CancellationToken canc : DB.Collection().FindAsync(session, mergedFilter, options, cancellation); } - private void AddTxtScoreToProjection(string propName) + void AddTxtScoreToProjection(string propName) { options.Projection ??= "{}"; diff --git a/MongoDB.Entities/Builders/Index.cs b/MongoDB.Entities/Builders/Index.cs index fcfbc78d4..3f4e58b9f 100644 --- a/MongoDB.Entities/Builders/Index.cs +++ b/MongoDB.Entities/Builders/Index.cs @@ -15,7 +15,7 @@ namespace MongoDB.Entities; public class Index where T : IEntity { internal List> Keys { get; set; } = new List>(); - private readonly CreateIndexOptions options = new() { Background = true }; + readonly CreateIndexOptions options = new() { Background = true }; /// /// Call this method to finalize defining the index after setting the index keys and options. @@ -132,13 +132,13 @@ public async Task DropAllAsync(CancellationToken cancellation = default) await DB.Collection().Indexes.DropAllAsync(cancellation).ConfigureAwait(false); } - private Task CreateAsync(CreateIndexModel model, CancellationToken cancellation = default) + Task CreateAsync(CreateIndexModel model, CancellationToken cancellation = default) { return DB.Collection().Indexes.CreateOneAsync(model, cancellationToken: cancellation); } } -internal class Key where T : IEntity +class Key where T : IEntity { internal string PropertyName { get; set; } internal KeyType Type { get; set; } diff --git a/MongoDB.Entities/Builders/PagedSearch.cs b/MongoDB.Entities/Builders/PagedSearch.cs index 9fb578b83..acbe8c1b1 100644 --- a/MongoDB.Entities/Builders/PagedSearch.cs +++ b/MongoDB.Entities/Builders/PagedSearch.cs @@ -27,15 +27,15 @@ internal PagedSearch(IClientSessionHandle? session, DictionaryThe type you'd like to project the results to. public class PagedSearch where T : IEntity { - private IAggregateFluent? fluentPipeline; - private FilterDefinition filter = Builders.Filter.Empty; - private readonly List> sorts = new(); - private readonly AggregateOptions options = new(); - private PipelineStageDefinition? projectionStage; - private readonly IClientSessionHandle? session; - private readonly Dictionary? globalFilters; - private bool ignoreGlobalFilters; - private int pageNumber = 1, pageSize = 100; + IAggregateFluent? fluentPipeline; + FilterDefinition filter = Builders.Filter.Empty; + readonly List> sorts = new(); + readonly AggregateOptions options = new(); + PipelineStageDefinition? projectionStage; + readonly IClientSessionHandle? session; + readonly Dictionary? globalFilters; + bool ignoreGlobalFilters; + int pageNumber = 1, pageSize = 100; internal PagedSearch(IClientSessionHandle? session, Dictionary? globalFilters) { @@ -215,7 +215,7 @@ public PagedSearch SortByTextScore(Expression>? } } - private void AddTxtScoreToProjection(string fieldName) + void AddTxtScoreToProjection(string fieldName) { if (projectionStage == null) { diff --git a/MongoDB.Entities/Builders/Replace.cs b/MongoDB.Entities/Builders/Replace.cs index 981706eb0..59ff3965b 100644 --- a/MongoDB.Entities/Builders/Replace.cs +++ b/MongoDB.Entities/Builders/Replace.cs @@ -16,14 +16,14 @@ namespace MongoDB.Entities; /// Any class that implements IEntity public class Replace where T : IEntity { - private FilterDefinition filter = Builders.Filter.Empty; - private ReplaceOptions options = new(); - private readonly IClientSessionHandle? session; - private readonly List> models = new(); - private readonly ModifiedBy? modifiedBy; - private readonly Dictionary? globalFilters; - private readonly Action? onSaveAction; - private bool ignoreGlobalFilters; + FilterDefinition filter = Builders.Filter.Empty; + ReplaceOptions options = new(); + readonly IClientSessionHandle? session; + readonly List> models = new(); + readonly ModifiedBy? modifiedBy; + readonly Dictionary? globalFilters; + readonly Action? onSaveAction; + bool ignoreGlobalFilters; internal Replace(IClientSessionHandle? session, ModifiedBy? modifiedBy, @@ -36,7 +36,7 @@ internal Replace(IClientSessionHandle? session, this.onSaveAction = onSaveAction; } - private T? Entity { get; set; } + T? Entity { get; set; } /// /// Specify an IEntity ID as the matching criteria @@ -252,7 +252,7 @@ public async Task ExecuteAsync(CancellationToken cancellation } } - private void SetModOnAndByValues() + void SetModOnAndByValues() { if (Cache.HasModifiedOn && Entity != null) ((IModifiedOn)Entity).ModifiedOn = DateTime.UtcNow; if (Cache.ModifiedByProp != null && modifiedBy != null) diff --git a/MongoDB.Entities/Builders/Update.cs b/MongoDB.Entities/Builders/Update.cs index 73da2e174..c3676a8f7 100644 --- a/MongoDB.Entities/Builders/Update.cs +++ b/MongoDB.Entities/Builders/Update.cs @@ -61,14 +61,14 @@ public void AddModification(Template template) /// Any class that implements IEntity public class Update : UpdateBase where T : IEntity { - private readonly List> stages = new(); - private FilterDefinition filter = Builders.Filter.Empty; - private UpdateOptions options = new(); - private readonly IClientSessionHandle? session; - private readonly List> models = new(); - private readonly Dictionary? globalFilters; - private readonly Action>? onUpdateAction; - private bool ignoreGlobalFilters; + readonly List> stages = new(); + FilterDefinition filter = Builders.Filter.Empty; + UpdateOptions options = new(); + readonly IClientSessionHandle? session; + readonly List> models = new(); + readonly Dictionary? globalFilters; + readonly Action>? onUpdateAction; + bool ignoreGlobalFilters; internal Update(IClientSessionHandle? session, Dictionary? globalFilters, @@ -451,7 +451,7 @@ public Task ExecutePipelineAsync(CancellationToken cancellation = cancellation); } - private bool ShouldSetModDate() + bool ShouldSetModDate() { //only set mod date by library if user hasn't done anything with the ModifiedOn property @@ -463,7 +463,7 @@ private bool ShouldSetModDate() .Contains($"\"{Cache.ModifiedOnPropName}\"")); } - private Task UpdateAsync(FilterDefinition filter, UpdateDefinition definition, UpdateOptions options, IClientSessionHandle? session = null, CancellationToken cancellation = default) + Task UpdateAsync(FilterDefinition filter, UpdateDefinition definition, UpdateOptions options, IClientSessionHandle? session = null, CancellationToken cancellation = default) { return session == null ? DB.Collection().UpdateManyAsync(filter, definition, options, cancellation) diff --git a/MongoDB.Entities/Builders/UpdateAndGet.cs b/MongoDB.Entities/Builders/UpdateAndGet.cs index e37bcb566..f7fa82095 100644 --- a/MongoDB.Entities/Builders/UpdateAndGet.cs +++ b/MongoDB.Entities/Builders/UpdateAndGet.cs @@ -30,13 +30,13 @@ internal UpdateAndGet(IClientSessionHandle? session, /// The type to project to public class UpdateAndGet : UpdateBase where T : IEntity { - private readonly List> stages = new(); - private FilterDefinition filter = Builders.Filter.Empty; + readonly List> stages = new(); + FilterDefinition filter = Builders.Filter.Empty; protected private readonly FindOneAndUpdateOptions options = new() { ReturnDocument = ReturnDocument.After }; - private readonly IClientSessionHandle? session; - private readonly Dictionary? globalFilters; - private readonly Action>? onUpdateAction; - private bool ignoreGlobalFilters; + readonly IClientSessionHandle? session; + readonly Dictionary? globalFilters; + readonly Action>? onUpdateAction; + bool ignoreGlobalFilters; internal UpdateAndGet(IClientSessionHandle? session, Dictionary? globalFilters, @@ -405,7 +405,7 @@ public UpdateAndGet IgnoreGlobalFilters() return await UpdateAndGetAsync(mergedFilter, Builders.Update.Pipeline(stages.ToArray()), options, session, cancellation); } - private bool ShouldSetModDate() + bool ShouldSetModDate() { //only set mod date by library if user hasn't done anything with the ModifiedOn property @@ -417,7 +417,7 @@ private bool ShouldSetModDate() .Contains($"\"{Cache.ModifiedOnPropName}\"")); } - private Task UpdateAndGetAsync(FilterDefinition filter, UpdateDefinition definition, FindOneAndUpdateOptions options, IClientSessionHandle? session = null, CancellationToken cancellation = default) + Task UpdateAndGetAsync(FilterDefinition filter, UpdateDefinition definition, FindOneAndUpdateOptions options, IClientSessionHandle? session = null, CancellationToken cancellation = default) { return session == null ? DB.Collection().FindOneAndUpdateAsync(filter, definition, options, cancellation) diff --git a/MongoDB.Entities/Core/Attributes/IdAttributes.cs b/MongoDB.Entities/Core/Attributes/IdAttributes.cs index 60a1ba27f..63edf66f2 100644 --- a/MongoDB.Entities/Core/Attributes/IdAttributes.cs +++ b/MongoDB.Entities/Core/Attributes/IdAttributes.cs @@ -25,7 +25,7 @@ public class AsObjectIdAttribute : BsonSerializerAttribute { public AsObjectIdAttribute() : base(typeof(ObjectIdSerializer)) { } - private class ObjectIdSerializer : SerializerBase, IRepresentationConfigurable + class ObjectIdSerializer : SerializerBase, IRepresentationConfigurable { public BsonType Representation { get; set; } @@ -79,7 +79,7 @@ public class AsBsonIdAttribute : BsonSerializerAttribute { public AsBsonIdAttribute() : base(typeof(ObjectIdSerializer)) { } - private class ObjectIdSerializer : SerializerBase, IRepresentationConfigurable + class ObjectIdSerializer : SerializerBase, IRepresentationConfigurable { public BsonType Representation { get; set; } diff --git a/MongoDB.Entities/Core/Cache.cs b/MongoDB.Entities/Core/Cache.cs index 4ef859895..ba37a118b 100644 --- a/MongoDB.Entities/Core/Cache.cs +++ b/MongoDB.Entities/Core/Cache.cs @@ -11,7 +11,7 @@ namespace MongoDB.Entities; -internal static class Cache where T : IEntity +static class Cache where T : IEntity { internal static string DBName { get; private set; } = null!; internal static IMongoDatabase Database { get; private set; } = null!; @@ -29,8 +29,8 @@ internal static class Cache where T : IEntity internal static Action IdSetter { get; private set; } = null!; internal static Func IdGetter { get; private set; } = null!; - private static PropertyInfo[] updatableProps = null!; - private static ProjectionDefinition requiredPropsProjection = null!; + static PropertyInfo[] updatableProps = null!; + static ProjectionDefinition requiredPropsProjection = null!; static Cache() { @@ -38,7 +38,7 @@ static Cache() DB.DefaultDbChanged += Initialize; } - private static void Initialize() + static void Initialize() { var type = typeof(T); @@ -145,7 +145,7 @@ internal static ProjectionDefinition CombineWithRequiredProps> SelectIdExpression(PropertyInfo idProp) + static Expression> SelectIdExpression(PropertyInfo idProp) { var parameter = Expression.Parameter(typeof(T), "t"); var property = Expression.Property(parameter, idProp); diff --git a/MongoDB.Entities/Core/Entities/FileEntity.cs b/MongoDB.Entities/Core/Entities/FileEntity.cs index 36d05b297..4b8af8519 100644 --- a/MongoDB.Entities/Core/Entities/FileEntity.cs +++ b/MongoDB.Entities/Core/Entities/FileEntity.cs @@ -17,7 +17,7 @@ namespace MongoDB.Entities; /// public abstract class FileEntity : Entity { - private DataStreamer? streamer; + DataStreamer? streamer; /// /// The total amount of data in bytes that has been uploaded so far @@ -50,7 +50,7 @@ public abstract class FileEntity : Entity } [Collection("[BINARY_CHUNKS]")] -internal class FileChunk : IEntity +class FileChunk : IEntity { [BsonId, ObjectId] public string ID { get; set; } = null!; @@ -72,12 +72,12 @@ public bool HasDefaultID() /// public class DataStreamer { - private static readonly HashSet indexedDBs = new(); + static readonly HashSet indexedDBs = new(); - private readonly FileEntity parent; - private readonly Type parentType; - private readonly IMongoDatabase db; - private readonly IMongoCollection chunkCollection; + readonly FileEntity parent; + readonly Type parentType; + readonly IMongoDatabase db; + readonly IMongoCollection chunkCollection; internal DataStreamer(FileEntity parent) { @@ -242,7 +242,7 @@ public Task DeleteBinaryChunks(IClientSessionHandle? session = null, Cancellatio : CleanUpAsync(session, cancellation); } - private Task CleanUpAsync(IClientSessionHandle? session, CancellationToken cancellation = default) + Task CleanUpAsync(IClientSessionHandle? session, CancellationToken cancellation = default) { parent.FileSize = 0; parent.ChunkCount = 0; @@ -252,7 +252,7 @@ private Task CleanUpAsync(IClientSessionHandle? session, CancellationToken cance : chunkCollection.DeleteManyAsync(session, c => c.FileID == parent.ID, null, cancellation); } - private Task FlushToDBAsync(IClientSessionHandle? session, StreamInfo streamInfo, bool isLastChunk = false, CancellationToken cancellation = default) + Task FlushToDBAsync(IClientSessionHandle? session, StreamInfo streamInfo, bool isLastChunk = false, CancellationToken cancellation = default) { if (!isLastChunk) { @@ -274,7 +274,7 @@ private Task FlushToDBAsync(IClientSessionHandle? session, StreamInfo streamInfo return Task.CompletedTask; } - private Task UpdateMetaDataAsync(IClientSessionHandle? session) + Task UpdateMetaDataAsync(IClientSessionHandle? session) { var collection = db.GetCollection(TypeMap.GetCollectionName(parentType)); var filter = Builders.Filter.Eq(e => e.ID, parent.ID); @@ -288,7 +288,7 @@ private Task UpdateMetaDataAsync(IClientSessionHandle? session) : collection.UpdateOneAsync(session, filter, update); } - private struct StreamInfo + struct StreamInfo { public FileChunk Doc { get; set; } public int ChunkSize { get; set; } diff --git a/MongoDB.Entities/Core/Entities/SequenceCounter.cs b/MongoDB.Entities/Core/Entities/SequenceCounter.cs index e05877ffe..e685747ed 100644 --- a/MongoDB.Entities/Core/Entities/SequenceCounter.cs +++ b/MongoDB.Entities/Core/Entities/SequenceCounter.cs @@ -4,7 +4,7 @@ namespace MongoDB.Entities; [Collection("[SEQUENCE_COUNTERS]")] -internal class SequenceCounter : IEntity +class SequenceCounter : IEntity { [BsonId] public string ID { get; set; } = null!; diff --git a/MongoDB.Entities/Core/IgnoreManyPropsConvention.cs b/MongoDB.Entities/Core/IgnoreManyPropsConvention.cs index f236afd81..7a2382ef7 100644 --- a/MongoDB.Entities/Core/IgnoreManyPropsConvention.cs +++ b/MongoDB.Entities/Core/IgnoreManyPropsConvention.cs @@ -3,7 +3,7 @@ namespace MongoDB.Entities; -internal class IgnoreManyPropsConvention : ConventionBase, IMemberMapConvention +class IgnoreManyPropsConvention : ConventionBase, IMemberMapConvention { public void Apply(BsonMemberMap mMap) { diff --git a/MongoDB.Entities/Core/Logic.cs b/MongoDB.Entities/Core/Logic.cs index 2ab8d4e80..01283cbd7 100644 --- a/MongoDB.Entities/Core/Logic.cs +++ b/MongoDB.Entities/Core/Logic.cs @@ -7,7 +7,7 @@ namespace MongoDB.Entities; -internal static class Logic +static class Logic { internal static IEnumerable> BuildUpdateDefs(T entity) where T : IEntity { diff --git a/MongoDB.Entities/Core/Serializers/Date.cs b/MongoDB.Entities/Core/Serializers/Date.cs index 152a6da98..5523b8b12 100644 --- a/MongoDB.Entities/Core/Serializers/Date.cs +++ b/MongoDB.Entities/Core/Serializers/Date.cs @@ -6,10 +6,10 @@ namespace MongoDB.Entities; -internal class DateSerializer : SerializerBase, IBsonDocumentSerializer +class DateSerializer : SerializerBase, IBsonDocumentSerializer { - private static readonly IBsonSerializer longSerializer = BsonSerializer.LookupSerializer(); - private static readonly IBsonSerializer dtSerializer = BsonSerializer.LookupSerializer(); + static readonly IBsonSerializer longSerializer = BsonSerializer.LookupSerializer(); + static readonly IBsonSerializer dtSerializer = BsonSerializer.LookupSerializer(); public override void Serialize(BsonSerializationContext ctx, BsonSerializationArgs args, Date date) { @@ -80,8 +80,8 @@ public bool TryGetMemberSerializationInfo(string memberName, out BsonSerializati /// public class Date { - private long ticks; - private DateTime date = new(); + long ticks; + DateTime date = new(); public long Ticks { get => ticks; diff --git a/MongoDB.Entities/Core/Serializers/FuzzyString.cs b/MongoDB.Entities/Core/Serializers/FuzzyString.cs index 73cff72f9..10173183d 100644 --- a/MongoDB.Entities/Core/Serializers/FuzzyString.cs +++ b/MongoDB.Entities/Core/Serializers/FuzzyString.cs @@ -6,9 +6,9 @@ namespace MongoDB.Entities; -internal class FuzzyStringSerializer : SerializerBase, IBsonDocumentSerializer +class FuzzyStringSerializer : SerializerBase, IBsonDocumentSerializer { - private static readonly IBsonSerializer strSerializer = BsonSerializer.LookupSerializer(); + static readonly IBsonSerializer strSerializer = BsonSerializer.LookupSerializer(); public override void Serialize(BsonSerializationContext ctx, BsonSerializationArgs args, FuzzyString fString) { diff --git a/MongoDB.Entities/Core/Template.cs b/MongoDB.Entities/Core/Template.cs index 13e45b859..a361e806d 100644 --- a/MongoDB.Entities/Core/Template.cs +++ b/MongoDB.Entities/Core/Template.cs @@ -236,16 +236,16 @@ public Template(string template) : base(template) { } /// public class Template { - private static readonly Regex regex = new("<.*?>", RegexOptions.Compiled); - private static readonly ConcurrentDictionary cache = new(); + static readonly Regex regex = new("<.*?>", RegexOptions.Compiled); + static readonly ConcurrentDictionary cache = new(); internal readonly StringBuilder builder; - private bool cacheHit, hasAppendedStages; - private readonly int cacheKey; - private readonly HashSet goalTags = new(); - private readonly HashSet missingTags = new(); - private readonly HashSet replacedTags = new(); - private readonly Dictionary valueTags = new(); + bool cacheHit, hasAppendedStages; + readonly int cacheKey; + readonly HashSet goalTags = new(); + readonly HashSet missingTags = new(); + readonly HashSet replacedTags = new(); + readonly Dictionary valueTags = new(); /// /// Initialize a command builder with the supplied template string. @@ -280,7 +280,7 @@ public Template(string template) } } - private Template ReplacePath(string path) + Template ReplacePath(string path) { var tag = $"<{path}>"; diff --git a/MongoDB.Entities/Core/Transaction.cs b/MongoDB.Entities/Core/Transaction.cs index d8b4b5dc0..1aaa9459f 100644 --- a/MongoDB.Entities/Core/Transaction.cs +++ b/MongoDB.Entities/Core/Transaction.cs @@ -28,7 +28,7 @@ public Transaction(string? database = null, ClientSessionOptions? options = null #region IDisposable Support - private bool disposedValue; + bool disposedValue; protected virtual void Dispose(bool disposing) { diff --git a/MongoDB.Entities/Core/TypeMap.cs b/MongoDB.Entities/Core/TypeMap.cs index c00abb582..94610d4d7 100644 --- a/MongoDB.Entities/Core/TypeMap.cs +++ b/MongoDB.Entities/Core/TypeMap.cs @@ -4,10 +4,10 @@ namespace MongoDB.Entities; -internal static class TypeMap +static class TypeMap { - private static readonly ConcurrentDictionary TypeToDBMap = new(); - private static readonly ConcurrentDictionary TypeToCollMap = new(); + static readonly ConcurrentDictionary TypeToDBMap = new(); + static readonly ConcurrentDictionary TypeToCollMap = new(); internal static void AddCollectionMapping(Type entityType, string collectionName) => TypeToCollMap[entityType] = collectionName; diff --git a/MongoDB.Entities/Core/Utilities/DoubleMetaphone.cs b/MongoDB.Entities/Core/Utilities/DoubleMetaphone.cs index f0cfa6eb2..2e395415e 100644 --- a/MongoDB.Entities/Core/Utilities/DoubleMetaphone.cs +++ b/MongoDB.Entities/Core/Utilities/DoubleMetaphone.cs @@ -5,105 +5,105 @@ namespace MongoDB.Entities; -internal static class DoubleMetaphone +static class DoubleMetaphone { - private static readonly string[] GN_KN_PN_WR_PS = new[] { "GN", "KN", "PN", "WR", "PS" }; - private static readonly string[] ACH = new[] { "ACH" }; - private static readonly string[] BACHER_MACHER = new[] { "BACHER", "MACHER" }; - private static readonly string[] CAESAR = new[] { "CAESAR" }; - private static readonly string[] CHIA = new[] { "CHIA" }; - private static readonly string[] CH = new[] { "CH" }; - private static readonly string[] CHAE = new[] { "CHAE" }; - private static readonly string[] HARAC_HARIS_HOR_HYM_HIA_HEM = new[] { "HARAC", "HARIS", "HOR", "HYM", "HIA", "HEM" }; - private static readonly string[] CHORE = new[] { "CHORE" }; - private static readonly string[] SCH = new[] { "SCH" }; - private static readonly string[] VAN__VON__SCH = new[] { "VAN ", "VON ", "SCH" }; - private static readonly string[] ORCHES_ARCHIT_ORCHID = new[] { "ORCHES", "ARCHIT", "ORCHID" }; - private static readonly string[] T_S = new[] { "T", "S" }; - private static readonly string[] A_O = new[] { "A", "O" }; - private static readonly string[] A_O_U_E = new[] { "A", "O", "U", "E" }; - private static readonly string[] L_R_N_M_B_H_F_V_W__ = new[] { "L", "R", "N", "M", "B", "H", "F", "V", "W", " " }; - private static readonly string[] MC = new[] { "MC" }; - private static readonly string[] CZ = new[] { "CZ" }; - private static readonly string[] WICZ = new[] { "WICZ" }; - private static readonly string[] CIA = new[] { "CIA" }; - private static readonly string[] CC = new[] { "CC" }; - private static readonly string[] I_E_H = new[] { "I", "E", "H" }; - private static readonly string[] HU = new[] { "HU" }; - private static readonly string[] UCCEE_UCCES = new[] { "UCCEE", "UCCES" }; - private static readonly string[] CK_CG_CQ = new[] { "CK", "CG", "CQ" }; - private static readonly string[] CI_CE_CY = new[] { "CI", "CE", "CY" }; - private static readonly string[] CIO_CIE_CIA = new[] { "CIO", "CIE", "CIA" }; - private static readonly string[] _C__Q__G = new[] { " C", " Q", " G" }; - private static readonly string[] C_K_Q = new[] { "C", "K", "Q" }; - private static readonly string[] CE_CI = new[] { "CE", "CI" }; - private static readonly string[] DG = new[] { "DG" }; - private static readonly string[] I_E_Y = new[] { "I", "E", "Y" }; - private static readonly string[] DT_DD = new[] { "DT", "DD" }; - private static readonly string[] B_H_D = new[] { "B", "H", "D" }; - private static readonly string[] B_H = new[] { "B", "H" }; - private static readonly string[] C_G_L_R_T = new[] { "C", "G", "L", "R", "T" }; - private static readonly string[] EY = new[] { "EY" }; - private static readonly string[] LI = new[] { "LI" }; - private static readonly string[] Y_ES_EP_EB_EL_EY_IB_IL_IN_IE_EI_ER = new[] { "Y", "ES", "EP", "EB", "EL", "EY", "IB", "IL", "IN", "IE", "EI", "ER" }; - private static readonly string[] Y_ER = new[] { "Y", "ER" }; - private static readonly string[] DANGER_RANGER_MANGER = new[] { "DANGER", "RANGER", "MANGER" }; - private static readonly string[] E_I = new[] { "E", "I" }; - private static readonly string[] RGY_OGY = new[] { "RGY", "OGY" }; - private static readonly string[] E_I_Y = new[] { "E", "I", "Y" }; - private static readonly string[] AGGI_OGGI = new[] { "AGGI", "OGGI" }; - private static readonly string[] ET = new[] { "ET" }; - private static readonly string[] JOSE = new[] { "JOSE" }; - private static readonly string[] SAN_ = new[] { "SAN " }; - private static readonly string[] L_T_K_S_N_M_B_Z = new[] { "L", "T", "K", "S", "N", "M", "B", "Z" }; - private static readonly string[] S_K_L = new[] { "S", "K", "L" }; - private static readonly string[] ILLO_ILLA_ALLE = new[] { "ILLO", "ILLA", "ALLE" }; - private static readonly string[] AS_OS = new[] { "AS", "OS" }; - private static readonly string[] ALLE = new[] { "ALLE" }; - private static readonly string[] UMB = new[] { "UMB" }; - private static readonly string[] P_B = new[] { "P", "B" }; - private static readonly string[] IE = new[] { "IE" }; - private static readonly string[] IER = new[] { "IER" }; - private static readonly string[] ER = new[] { "ER" }; - private static readonly string[] ME_MA = new[] { "ME", "MA" }; - private static readonly string[] ISL_YSL = new[] { "ISL", "YSL" }; - private static readonly string[] SUGAR = new[] { "SUGAR" }; - private static readonly string[] SH = new[] { "SH" }; - private static readonly string[] HEIM_HOEK_HOLM_HOLZ = new[] { "HEIM", "HOEK", "HOLM", "HOLZ" }; - private static readonly string[] SIO_SIA = new[] { "SIO", "SIA" }; - private static readonly string[] SIAN = new[] { "SIAN" }; - private static readonly string[] M_N_L_W = new[] { "M", "N", "L", "W" }; - private static readonly string[] SC = new[] { "SC" }; - private static readonly string[] OO_ER_EN_UY_ED_EM = new[] { "OO", "ER", "EN", "UY", "ED", "EM" }; - private static readonly string[] ER_EN = new[] { "ER", "EN" }; - private static readonly string[] AI_OI = new[] { "AI", "OI" }; - private static readonly string[] S_Z = new[] { "S", "Z" }; - private static readonly string[] TION = new[] { "TION" }; - private static readonly string[] TIA_TCH = new[] { "TIA", "TCH" }; - private static readonly string[] TH_TTH = new[] { "TH", "TTH" }; - private static readonly string[] OM_AM = new[] { "OM", "AM" }; - private static readonly string[] T_D = new[] { "T", "D" }; - private static readonly string[] WR = new[] { "WR" }; - private static readonly string[] WH = new[] { "WH" }; - private static readonly string[] EWSKI_EWSKY_OWSKI_OWSKY = new[] { "EWSKI", "EWSKY", "OWSKI", "OWSKY" }; - private static readonly string[] WICZ_WITZ = new[] { "WICZ", "WITZ" }; - private static readonly string[] IAU_EAU = new[] { "IAU", "EAU" }; - private static readonly string[] AU_OU = new[] { "AU", "OU" }; - private static readonly string[] C_X = new[] { "C", "X" }; - private static readonly string[] ZO_ZI_ZA = new[] { "ZO", "ZI", "ZA" }; - - private static readonly string[] EmptyKeys = new string[0]; - private const int MaxLength = 4; - - private static readonly Regex regex = new(@"\w(? 0) @@ -119,7 +119,7 @@ private static void Add(string main, string alternate, ref StringBuilder sbPrima } } - private static bool Match(string stringRenamed, int pos, string[] strings) + static bool Match(string stringRenamed, int pos, string[] strings) { if (0 <= pos && pos < stringRenamed.Length) { @@ -132,17 +132,17 @@ private static bool Match(string stringRenamed, int pos, string[] strings) return false; } - private static bool Match(string stringRenamed, int pos, char c) + static bool Match(string stringRenamed, int pos, char c) { return 0 <= pos && pos < stringRenamed.Length && stringRenamed[pos] == c; } - private static bool IsSlavoGermanic(string stringRenamed) + static bool IsSlavoGermanic(string stringRenamed) { return (stringRenamed.IndexOf('W') >= 0) || (stringRenamed.IndexOf('K') >= 0) || (stringRenamed.IndexOf("CZ", StringComparison.Ordinal) >= 0) || (stringRenamed.IndexOf("WITZ", StringComparison.Ordinal) >= 0); } - private static bool IsVowel(string stringRenamed, int pos) + static bool IsVowel(string stringRenamed, int pos) { if (pos < 0 || stringRenamed.Length <= pos) return false; @@ -151,7 +151,7 @@ private static bool IsVowel(string stringRenamed, int pos) return c is 'A' or 'E' or 'I' or 'O' or 'U'; } - private static string[] BuildKeys(string word) + static string[] BuildKeys(string word) { if (string.IsNullOrEmpty(word)) return EmptyKeys; diff --git a/MongoDB.Entities/Core/Utilities/LevenshteinDistance.cs b/MongoDB.Entities/Core/Utilities/LevenshteinDistance.cs index 47c7d25ec..8f6e5c566 100644 --- a/MongoDB.Entities/Core/Utilities/LevenshteinDistance.cs +++ b/MongoDB.Entities/Core/Utilities/LevenshteinDistance.cs @@ -1,9 +1,9 @@ namespace MongoDB.Entities; -internal class Levenshtein +class Levenshtein { - private readonly string storedValue; - private readonly int[] costs; + readonly string storedValue; + readonly int[] costs; public Levenshtein(string value) { diff --git a/MongoDB.Entities/Core/Utilities/Prop.cs b/MongoDB.Entities/Core/Utilities/Prop.cs index 0697ca4b9..a4ccc9fc5 100644 --- a/MongoDB.Entities/Core/Utilities/Prop.cs +++ b/MongoDB.Entities/Core/Utilities/Prop.cs @@ -9,12 +9,12 @@ namespace MongoDB.Entities; /// public static class Prop { - private static readonly Regex rxOne = new(@"(?:\.(?:\w+(?:[[(]\d+[)\]])?))+", RegexOptions.Compiled);//matched result: One.Two[1].Three.get_Item(2).Four - private static readonly Regex rxTwo = new(@".get_Item\((\d+)\)", RegexOptions.Compiled);//replaced result: One.Two[1].Three[2].Four - private static readonly Regex rxThree = new(@"\[\d+\]", RegexOptions.Compiled); - private static readonly Regex rxFour = new(@"\[(\d+)\]", RegexOptions.Compiled); + static readonly Regex rxOne = new(@"(?:\.(?:\w+(?:[[(]\d+[)\]])?))+", RegexOptions.Compiled);//matched result: One.Two[1].Three.get_Item(2).Four + static readonly Regex rxTwo = new(@".get_Item\((\d+)\)", RegexOptions.Compiled);//replaced result: One.Two[1].Three[2].Four + static readonly Regex rxThree = new(@"\[\d+\]", RegexOptions.Compiled); + static readonly Regex rxFour = new(@"\[(\d+)\]", RegexOptions.Compiled); - private static string ToLowerCaseLetter(long n) + static string ToLowerCaseLetter(long n) { if (n < 0) throw new NotSupportedException("Value must be greater than 0!"); @@ -31,7 +31,7 @@ private static string ToLowerCaseLetter(long n) return val!; } - private static void ThrowIfInvalid(Expression> expression) + static void ThrowIfInvalid(Expression> expression) { if (expression == null) throw new ArgumentNullException(nameof(expression), "The supplied expression is null!"); @@ -40,7 +40,7 @@ private static void ThrowIfInvalid(Expression> expression) throw new ArgumentException("Cannot generate property path from lambda parameter!"); } - private static string GetPath(Expression> expression) + static string GetPath(Expression> expression) { ThrowIfInvalid(expression); diff --git a/MongoDB.Entities/Core/Watcher.cs b/MongoDB.Entities/Core/Watcher.cs index afa6f819e..d0996d47d 100644 --- a/MongoDB.Entities/Core/Watcher.cs +++ b/MongoDB.Entities/Core/Watcher.cs @@ -78,10 +78,10 @@ public class Watcher where T : IEntity /// public BsonDocument? ResumeToken => options?.StartAfter; - private PipelineDefinition, ChangeStreamDocument> pipeline = null!; - private ChangeStreamOptions? options; - private bool resume; - private CancellationToken cancelToken; + PipelineDefinition, ChangeStreamDocument> pipeline = null!; + ChangeStreamOptions? options; + bool resume; + CancellationToken cancelToken; internal Watcher(string name) => Name = name; @@ -229,7 +229,7 @@ public void StartWithToken( CancellationToken cancellation = default) => Init(resumeToken, eventTypes, filter(Builders>.Filter), projection, batchSize, false, true, cancellation); - private void Init( + void Init( BsonDocument? resumeToken, EventType eventTypes, FilterDefinition> filter, @@ -313,7 +313,7 @@ private void Init( StartWatching(); } - private static ProjectionDefinition, ChangeStreamDocument> BuildProjection(Expression> projection) + static ProjectionDefinition, ChangeStreamDocument> BuildProjection(Expression> projection) { var rendered = Builders.Projection .Expression(projection) @@ -368,7 +368,7 @@ public void ReStart(BsonDocument? resumeToken = null) StartWatching(); } - private void StartWatching() + void StartWatching() { //note : don't use Task.Factory.StartNew with long running option //reason: http://blog.i3arnon.com/2015/07/02/task-run-long-running/ diff --git a/MongoDB.Entities/DB/DB.Delete.cs b/MongoDB.Entities/DB/DB.Delete.cs index c3c135ef1..7241a0123 100644 --- a/MongoDB.Entities/DB/DB.Delete.cs +++ b/MongoDB.Entities/DB/DB.Delete.cs @@ -11,9 +11,9 @@ namespace MongoDB.Entities; public static partial class DB { - private static readonly int deleteBatchSize = 100000; + static readonly int deleteBatchSize = 100000; - private static async Task DeleteCascadingAsync(IEnumerable IDs, + static async Task DeleteCascadingAsync(IEnumerable IDs, IClientSessionHandle? session = null, CancellationToken cancellation = default) where T : IEntity { @@ -192,7 +192,7 @@ public static async Task DeleteAsync(FilterDefinition filter return res; } - private static List ValidateCursor(List idObjects) + static List ValidateCursor(List idObjects) { if (idObjects.Any() && idObjects[0] is ExpandoObject) { @@ -207,7 +207,7 @@ private static List ValidateCursor(List idObjects) return idObjects; } - private static void ThrowIfCancellationNotSupported(IClientSessionHandle? session = null, CancellationToken cancellation = default) + static void ThrowIfCancellationNotSupported(IClientSessionHandle? session = null, CancellationToken cancellation = default) { if (cancellation != default && session == null) throw new NotSupportedException("Cancellation is only supported within transactions for delete operations!"); diff --git a/MongoDB.Entities/DB/DB.Migrate.cs b/MongoDB.Entities/DB/DB.Migrate.cs index 560e6cfe2..ca5d31a4e 100644 --- a/MongoDB.Entities/DB/DB.Migrate.cs +++ b/MongoDB.Entities/DB/DB.Migrate.cs @@ -38,7 +38,7 @@ public static Task MigrationsAsync(IEnumerable migrations) return Execute(migrations); } - private static Task Migrate(Type? targetType) + static Task Migrate(Type? targetType) { IEnumerable assemblies; @@ -76,7 +76,7 @@ private static Task Migrate(Type? targetType) : Execute(types.Select(t => (IMigration)Activator.CreateInstance(t))); } - private static async Task Execute(IEnumerable migrations) + static async Task Execute(IEnumerable migrations) { var lastMigNum = await Find() diff --git a/MongoDB.Entities/DB/DB.Save.cs b/MongoDB.Entities/DB/DB.Save.cs index 365aab7a4..076ef71ca 100644 --- a/MongoDB.Entities/DB/DB.Save.cs +++ b/MongoDB.Entities/DB/DB.Save.cs @@ -10,8 +10,8 @@ namespace MongoDB.Entities; public static partial class DB { - private static readonly BulkWriteOptions unOrdBlkOpts = new() { IsOrdered = false }; - private static readonly UpdateOptions updateOptions = new() { IsUpsert = true }; + static readonly BulkWriteOptions unOrdBlkOpts = new() { IsOrdered = false }; + static readonly UpdateOptions updateOptions = new() { IsUpsert = true }; /// /// Saves a complete entity replacing an existing entity or creating a new one if it does not exist. @@ -247,7 +247,7 @@ public static Task SavePreservingAsync(T entity, IClientSession : Collection().UpdateOneAsync(session, filter, Builders.Update.Combine(defs), updateOptions, cancellation); } - private static Task SavePartial(T entity, IEnumerable propNames, IClientSessionHandle? session, CancellationToken cancellation, bool excludeMode = false) where T : IEntity + static Task SavePartial(T entity, IEnumerable propNames, IClientSessionHandle? session, CancellationToken cancellation, bool excludeMode = false) where T : IEntity { PrepAndCheckIfInsert(entity); //just prep. we don't care about inserts here var filter = Builders.Filter.Eq(entity.GetIdName(), entity.GetId()); @@ -257,7 +257,7 @@ private static Task SavePartial(T entity, IEnumerable p : Collection().UpdateOneAsync(session, filter, Builders.Update.Combine(Logic.BuildUpdateDefs(entity, propNames, excludeMode)), updateOptions, cancellation); } - private static Task> SavePartial(IEnumerable entities, IEnumerable propNames, IClientSessionHandle? session, CancellationToken cancellation, bool excludeMode = false) where T : IEntity + static Task> SavePartial(IEnumerable entities, IEnumerable propNames, IClientSessionHandle? session, CancellationToken cancellation, bool excludeMode = false) where T : IEntity { var models = new List>(entities.Count()); @@ -276,7 +276,7 @@ private static Task> SavePartial(IEnumerable entities, : Collection().BulkWriteAsync(session, models, unOrdBlkOpts, cancellation); } - private static bool PrepAndCheckIfInsert(T entity) where T : IEntity + static bool PrepAndCheckIfInsert(T entity) where T : IEntity { if (entity.HasDefaultID()) { diff --git a/MongoDB.Entities/DB/DB.cs b/MongoDB.Entities/DB/DB.cs index cfdaea2b5..2ad8b46f0 100644 --- a/MongoDB.Entities/DB/DB.cs +++ b/MongoDB.Entities/DB/DB.cs @@ -34,8 +34,8 @@ static DB() internal static event Action? DefaultDbChanged; - private static readonly ConcurrentDictionary dbs = new(); - private static IMongoDatabase? defaultDb; + static readonly ConcurrentDictionary dbs = new(); + static IMongoDatabase? defaultDb; /// /// Initializes a MongoDB connection with the given connection parameters. diff --git a/MongoDB.Entities/DBContext/DBContext.Pipeline.cs b/MongoDB.Entities/DBContext/DBContext.Pipeline.cs index bde599098..b97a3f514 100644 --- a/MongoDB.Entities/DBContext/DBContext.Pipeline.cs +++ b/MongoDB.Entities/DBContext/DBContext.Pipeline.cs @@ -69,7 +69,7 @@ public Task PipelineFirstAsync(Template templat return DB.PipelineFirstAsync(MergeGlobalFilter(template, ignoreGlobalFilters), options, Session, cancellation); } - private Template MergeGlobalFilter(Template template, bool ignoreGlobalFilters) where T : IEntity + Template MergeGlobalFilter(Template template, bool ignoreGlobalFilters) where T : IEntity { //WARNING: this has to do the same thing as Logic.MergeGlobalFilter method // if the following logic changes, update the other method also diff --git a/MongoDB.Entities/DBContext/DBContext.Save.cs b/MongoDB.Entities/DBContext/DBContext.Save.cs index 0699d1f0b..63a1e7f84 100644 --- a/MongoDB.Entities/DBContext/DBContext.Save.cs +++ b/MongoDB.Entities/DBContext/DBContext.Save.cs @@ -189,7 +189,7 @@ public Task SavePreservingAsync(T entity, CancellationToken can return DB.SavePreservingAsync(entity, Session, cancellation); } - private void SetModifiedBySingle(T entity) where T : IEntity + void SetModifiedBySingle(T entity) where T : IEntity { ThrowIfModifiedByIsEmpty(); Cache.ModifiedByProp?.SetValue( @@ -199,7 +199,7 @@ private void SetModifiedBySingle(T entity) where T : IEntity // to be able to correctly deserialize a user supplied derived/sub class of ModifiedOn. } - private void SetModifiedByMultiple(IEnumerable entities) where T : IEntity + void SetModifiedByMultiple(IEnumerable entities) where T : IEntity { if (Cache.ModifiedByProp is null) return; diff --git a/MongoDB.Entities/DBContext/DBContext.cs b/MongoDB.Entities/DBContext/DBContext.cs index 5c1518cd4..8f5ba50f6 100644 --- a/MongoDB.Entities/DBContext/DBContext.cs +++ b/MongoDB.Entities/DBContext/DBContext.cs @@ -19,8 +19,8 @@ public partial class DBContext /// public ModifiedBy? ModifiedBy { get; set; } - private static Type[]? allEntitiyTypes; - private Dictionary? globalFilters; + static Type[]? allEntitiyTypes; + Dictionary? globalFilters; /// /// Initializes a DBContext instance with the given connection parameters. @@ -251,7 +251,7 @@ protected void SetGlobalFilterForInterface(string jsonString, bool p } } - private static Type[] GetAllEntityTypes() + static Type[] GetAllEntityTypes() { var excludes = new[] { @@ -275,7 +275,7 @@ private static Type[] GetAllEntityTypes() .ToArray(); } - private void ThrowIfModifiedByIsEmpty() where T : IEntity + void ThrowIfModifiedByIsEmpty() where T : IEntity { if (Cache.ModifiedByProp != null && ModifiedBy is null) { @@ -284,7 +284,7 @@ private void ThrowIfModifiedByIsEmpty() where T : IEntity } } - private void AddFilter(Type type, (object filterDef, bool prepend) filter) + void AddFilter(Type type, (object filterDef, bool prepend) filter) { globalFilters ??= new Dictionary(); diff --git a/MongoDB.Entities/Extensions/Entity.cs b/MongoDB.Entities/Extensions/Entity.cs index dd794b0de..3e1985f8d 100644 --- a/MongoDB.Entities/Extensions/Entity.cs +++ b/MongoDB.Entities/Extensions/Entity.cs @@ -18,7 +18,7 @@ namespace MongoDB.Entities; /// public static partial class Extensions { - private class Holder + class Holder { public T Data { get; set; } @@ -26,7 +26,7 @@ public Holder(T data) => Data = data; } - private static T Duplicate(this T source) + static T Duplicate(this T source) { return BsonSerializer.Deserialize>( new Holder(source).ToBson()).Data; diff --git a/MongoDB.Entities/Relationships/Many.Fluent.cs b/MongoDB.Entities/Relationships/Many.Fluent.cs index 76cd54d61..0ede4b68d 100644 --- a/MongoDB.Entities/Relationships/Many.Fluent.cs +++ b/MongoDB.Entities/Relationships/Many.Fluent.cs @@ -161,7 +161,7 @@ public IAggregateFluent ChildrenFluent(IClientSessionHandle? session = n .ReplaceRoot(j => j.Results[0]); } - private class Joined : JoinRecord + class Joined : JoinRecord { public T[] Results { get; set; } = null!; } diff --git a/MongoDB.Entities/Relationships/Many.cs b/MongoDB.Entities/Relationships/Many.cs index c64a114ae..b4e5f3057 100644 --- a/MongoDB.Entities/Relationships/Many.cs +++ b/MongoDB.Entities/Relationships/Many.cs @@ -29,9 +29,9 @@ public abstract class ManyBase /// The type of the parent public sealed partial class Many : ManyBase where TChild : IEntity where TParent : IEntity { - private static readonly BulkWriteOptions unOrdBlkOpts = new() { IsOrdered = false }; - private bool isInverse; - private TParent parent = default!; + static readonly BulkWriteOptions unOrdBlkOpts = new() { IsOrdered = false }; + bool isInverse; + TParent parent = default!; /// /// Gets the IMongoCollection of JoinRecords for this relationship. @@ -70,7 +70,7 @@ internal Many(object parent, string property) Init((dynamic)parent, property); } - private void Init(TParent parent, string property) + void Init(TParent parent, string property) { if (DB.DatabaseName() != DB.DatabaseName()) throw new NotSupportedException("Cross database relationships are not supported!"); @@ -98,7 +98,7 @@ internal Many(object parent, string propertyParent, string propertyChild, bool i Init((dynamic)parent, propertyParent, propertyChild, isInverse); } - private void Init(TParent parent, string propertyParent, string propertyChild, bool isInverse) + void Init(TParent parent, string propertyParent, string propertyChild, bool isInverse) { this.parent = parent; this.isInverse = isInverse; @@ -127,7 +127,7 @@ public void VB_InitManyToMany( } #endregion - private static Task CreateIndexesAsync(IMongoCollection collection) + static Task CreateIndexesAsync(IMongoCollection collection) { //only create indexes once (best effort) per unique ref collection if (!indexedCollections.Contains(collection.CollectionNamespace.CollectionName)) diff --git a/MongoDB.Entities/Relationships/One.cs b/MongoDB.Entities/Relationships/One.cs index 821567b01..2ef51f694 100644 --- a/MongoDB.Entities/Relationships/One.cs +++ b/MongoDB.Entities/Relationships/One.cs @@ -91,7 +91,7 @@ public async Task ToEntityAsync(Func, Projecti .SingleOrDefault(); } - private object TransformID() + object TransformID() { return ID is string vStr && vStr.Length == 24 && ObjectId.TryParse(vStr, out var oID) ? oID : ID; } diff --git a/Tests/EntityIdTests/TestCounting.cs b/Tests/EntityIdTests/TestCounting.cs index 3880283d0..9405ad65c 100644 --- a/Tests/EntityIdTests/TestCounting.cs +++ b/Tests/EntityIdTests/TestCounting.cs @@ -8,9 +8,9 @@ namespace MongoDB.Entities.Tests; [TestClass] public class CountingEntity { - private DBContext db; + DBContext db; - private Task Init(string guid) + Task Init(string guid) { db = new MyDBEntity(); diff --git a/Tests/EntityIdTests/TestMultiDb.cs b/Tests/EntityIdTests/TestMultiDb.cs index 1de5d4a39..b0dbae86c 100644 --- a/Tests/EntityIdTests/TestMultiDb.cs +++ b/Tests/EntityIdTests/TestMultiDb.cs @@ -10,7 +10,7 @@ namespace MongoDB.Entities.Tests; [TestClass] public class MultiDbEntity { - private const string dbName = "mongodb-entities-test-multi"; + const string dbName = "mongodb-entities-test-multi"; [TestMethod] public async Task save_entity_works() diff --git a/Tests/EntityIdTests/TestPagedSearch.cs b/Tests/EntityIdTests/TestPagedSearch.cs index 0fd02f434..30ccc477a 100644 --- a/Tests/EntityIdTests/TestPagedSearch.cs +++ b/Tests/EntityIdTests/TestPagedSearch.cs @@ -26,7 +26,7 @@ public async Task empty_results() Assert.IsTrue(Results.Count == 0); } - private static Task SeedData(string guid) + static Task SeedData(string guid) { var list = new List(10); @@ -98,7 +98,7 @@ public async Task got_results_with_fluent() Assert.IsTrue(Results.Count > 0); } - private class BookResult + class BookResult { public string BookTitle { get; set; } public string BookID { get; set; } diff --git a/Tests/EntityIdTests/TestSaving.cs b/Tests/EntityIdTests/TestSaving.cs index deb93c528..695eb4cdc 100644 --- a/Tests/EntityIdTests/TestSaving.cs +++ b/Tests/EntityIdTests/TestSaving.cs @@ -610,7 +610,7 @@ public async Task find_by_filter_returns_correct_documents() Assert.AreEqual(three.Name, res[0].Name); } - private class Test { public string Tester { get; set; } } + class Test { public string Tester { get; set; } } [TestMethod] public async Task find_with_projection_to_custom_type_works() { diff --git a/Tests/Int64Tests/TestCounting.cs b/Tests/Int64Tests/TestCounting.cs index 8a5e51a2c..a03c1b827 100644 --- a/Tests/Int64Tests/TestCounting.cs +++ b/Tests/Int64Tests/TestCounting.cs @@ -8,9 +8,9 @@ namespace MongoDB.Entities.Tests; [TestClass] public class CountingInt64 { - private DBContext db; + DBContext db; - private Task Init(string Int64) + Task Init(string Int64) { db = new MyDBInt64(); diff --git a/Tests/Int64Tests/TestMultiDb.cs b/Tests/Int64Tests/TestMultiDb.cs index 780fefe22..6147043a6 100644 --- a/Tests/Int64Tests/TestMultiDb.cs +++ b/Tests/Int64Tests/TestMultiDb.cs @@ -10,7 +10,7 @@ namespace MongoDB.Entities.Tests; [TestClass] public class MultiDbInt64 { - private const string dbName = "mongodb-entities-test-multi"; + const string dbName = "mongodb-entities-test-multi"; [TestMethod] public async Task save_Int64_works() diff --git a/Tests/Int64Tests/TestPagedSearch.cs b/Tests/Int64Tests/TestPagedSearch.cs index 92bf20fc6..85d62e8f8 100644 --- a/Tests/Int64Tests/TestPagedSearch.cs +++ b/Tests/Int64Tests/TestPagedSearch.cs @@ -26,7 +26,7 @@ public async Task empty_results() Assert.IsTrue(Results.Count == 0); } - private static Task SeedData(string Int64) + static Task SeedData(string Int64) { var list = new List(10); @@ -98,7 +98,7 @@ public async Task got_results_with_fluent() Assert.IsTrue(Results.Count > 0); } - private class BookResult + class BookResult { public string BookTitle { get; set; } public Int64? BookID { get; set; } diff --git a/Tests/Int64Tests/TestSaving.cs b/Tests/Int64Tests/TestSaving.cs index 61a43c56d..dc24b5e08 100644 --- a/Tests/Int64Tests/TestSaving.cs +++ b/Tests/Int64Tests/TestSaving.cs @@ -610,7 +610,7 @@ public async Task find_by_filter_returns_correct_documents() Assert.AreEqual(three.Name, res[0].Name); } - private class Test { public string Tester { get; set; } } + class Test { public string Tester { get; set; } } [TestMethod] public async Task find_with_projection_to_custom_type_works() { diff --git a/Tests/ObjectIdTests/TestCounting.cs b/Tests/ObjectIdTests/TestCounting.cs index 4fecb941e..45d3185f2 100644 --- a/Tests/ObjectIdTests/TestCounting.cs +++ b/Tests/ObjectIdTests/TestCounting.cs @@ -8,9 +8,9 @@ namespace MongoDB.Entities.Tests; [TestClass] public class CountingObjectId { - private DBContext db; + DBContext db; - private Task Init(string ObjectId) + Task Init(string ObjectId) { db = new MyDBObjectId(); diff --git a/Tests/ObjectIdTests/TestMultiDb.cs b/Tests/ObjectIdTests/TestMultiDb.cs index cc408c41a..e6cf872d8 100644 --- a/Tests/ObjectIdTests/TestMultiDb.cs +++ b/Tests/ObjectIdTests/TestMultiDb.cs @@ -10,7 +10,7 @@ namespace MongoDB.Entities.Tests; [TestClass] public class MultiDbObjectId { - private const string dbName = "mongodb-entities-test-multi"; + const string dbName = "mongodb-entities-test-multi"; [TestMethod] public async Task save_ObjectId_works() diff --git a/Tests/ObjectIdTests/TestPagedSearch.cs b/Tests/ObjectIdTests/TestPagedSearch.cs index 605ea7667..e7dd9f401 100644 --- a/Tests/ObjectIdTests/TestPagedSearch.cs +++ b/Tests/ObjectIdTests/TestPagedSearch.cs @@ -27,7 +27,7 @@ public async Task empty_results() Assert.IsTrue(Results.Count == 0); } - private static Task SeedData(string ObjectId) + static Task SeedData(string ObjectId) { var list = new List(10); @@ -99,7 +99,7 @@ public async Task got_results_with_fluent() Assert.IsTrue(Results.Count > 0); } - private class BookResult + class BookResult { public string BookTitle { get; set; } public ObjectId? BookID { get; set; } diff --git a/Tests/ObjectIdTests/TestSaving.cs b/Tests/ObjectIdTests/TestSaving.cs index 8f6d59333..f2410497a 100644 --- a/Tests/ObjectIdTests/TestSaving.cs +++ b/Tests/ObjectIdTests/TestSaving.cs @@ -610,7 +610,7 @@ public async Task find_by_filter_returns_correct_documents() Assert.AreEqual(three.Name, res[0].Name); } - private class Test { public string Tester { get; set; } } + class Test { public string Tester { get; set; } } [TestMethod] public async Task find_with_projection_to_custom_type_works() { diff --git a/Tests/TestFileEntity.cs b/Tests/TestFileEntity.cs index 990394ab8..313e5fb00 100644 --- a/Tests/TestFileEntity.cs +++ b/Tests/TestFileEntity.cs @@ -14,7 +14,7 @@ namespace MongoDB.Entities.Tests; [TestClass] public class FileEntities { - private const string dbName = "mongodb-entities-test-multi"; + const string dbName = "mongodb-entities-test-multi"; [TestCategory("SkipWhenLiveUnitTesting")] //[TestMethod] diff --git a/Tests/UuidTests/TestCounting.cs b/Tests/UuidTests/TestCounting.cs index f075d4953..29000d551 100644 --- a/Tests/UuidTests/TestCounting.cs +++ b/Tests/UuidTests/TestCounting.cs @@ -8,9 +8,9 @@ namespace MongoDB.Entities.Tests; [TestClass] public class CountingUuid { - private DBContext db; + DBContext db; - private Task Init(string guid) + Task Init(string guid) { db = new MyDBUuid(); diff --git a/Tests/UuidTests/TestMultiDb.cs b/Tests/UuidTests/TestMultiDb.cs index 6c9085bed..ba74b33a0 100644 --- a/Tests/UuidTests/TestMultiDb.cs +++ b/Tests/UuidTests/TestMultiDb.cs @@ -10,7 +10,7 @@ namespace MongoDB.Entities.Tests; [TestClass] public class MultiDbUuid { - private const string dbName = "mongodb-entities-test-multi"; + const string dbName = "mongodb-entities-test-multi"; [TestMethod] public async Task save_Guid_works() diff --git a/Tests/UuidTests/TestPagedSearch.cs b/Tests/UuidTests/TestPagedSearch.cs index 2286f7af3..94b49334b 100644 --- a/Tests/UuidTests/TestPagedSearch.cs +++ b/Tests/UuidTests/TestPagedSearch.cs @@ -26,7 +26,7 @@ public async Task empty_results() Assert.IsTrue(Results.Count == 0); } - private static Task SeedData(string guid) + static Task SeedData(string guid) { var list = new List(10); @@ -98,7 +98,7 @@ public async Task got_results_with_fluent() Assert.IsTrue(Results.Count > 0); } - private class BookResult + class BookResult { public string BookTitle { get; set; } public string? BookID { get; set; } diff --git a/Tests/UuidTests/TestSaving.cs b/Tests/UuidTests/TestSaving.cs index b89d269be..e46784f90 100644 --- a/Tests/UuidTests/TestSaving.cs +++ b/Tests/UuidTests/TestSaving.cs @@ -610,7 +610,7 @@ public async Task find_by_filter_returns_correct_documents() Assert.AreEqual(three.Name, res[0].Name); } - private class Test { public string Tester { get; set; } } + class Test { public string Tester { get; set; } } [TestMethod] public async Task find_with_projection_to_custom_type_works() {