From 68e8b6f1716473fef696c6eb627d67772f2f0fca Mon Sep 17 00:00:00 2001 From: sergergood Date: Wed, 31 Jan 2024 14:31:45 +0300 Subject: [PATCH] Using FrozenDictionary --- .../RepoDb/Cachers/Types/DbFieldCollection.cs | 17 +++++++++-------- RepoDb.Core/RepoDb/RepoDb.csproj | 4 ++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/RepoDb.Core/RepoDb/Cachers/Types/DbFieldCollection.cs b/RepoDb.Core/RepoDb/Cachers/Types/DbFieldCollection.cs index 473044668..610688fd6 100644 --- a/RepoDb.Core/RepoDb/Cachers/Types/DbFieldCollection.cs +++ b/RepoDb.Core/RepoDb/Cachers/Types/DbFieldCollection.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Frozen; using System.Collections.Generic; using System.Linq; using RepoDb.Extensions; @@ -15,8 +16,8 @@ public class DbFieldCollection private readonly IReadOnlyList dbFields; private readonly Lazy> lazyFields; private readonly Lazy lazyIdentity; - private readonly Lazy> lazyMapByName; - private readonly Lazy> lazyMapByUnquotedName; + private readonly Lazy> lazyMapByName; + private readonly Lazy> lazyMapByUnquotedName; private readonly Lazy lazyPrimary; /// @@ -31,8 +32,8 @@ public DbFieldCollection(IEnumerable dbFields, IDbSetting dbSetting) lazyPrimary = new Lazy(GetPrimaryDbField); lazyIdentity = new Lazy(GetIdentityDbField); - lazyMapByName = new Lazy>(GetDbFieldsMappedByName); - lazyMapByUnquotedName = new Lazy>(GetDbFieldsMappedByUnquotedName); + lazyMapByName = new Lazy>(GetDbFieldsMappedByName); + lazyMapByUnquotedName = new Lazy>(GetDbFieldsMappedByUnquotedName); lazyFields = new Lazy>(GetDbFieldsAsFields); } @@ -90,11 +91,11 @@ public DbField GetByUnquotedName(string name) return dbField; } - private Dictionary GetDbFieldsMappedByName() => - dbFields.ToDictionary(df => df.Name, df => df, StringComparer.OrdinalIgnoreCase); + private FrozenDictionary GetDbFieldsMappedByName() => + dbFields.ToFrozenDictionary(df => df.Name, df => df, StringComparer.OrdinalIgnoreCase); - private Dictionary GetDbFieldsMappedByUnquotedName() => - dbFields.ToDictionary(df => df.Name.AsUnquoted(true, dbSetting), df => df, StringComparer.OrdinalIgnoreCase); + private FrozenDictionary GetDbFieldsMappedByUnquotedName() => + dbFields.ToFrozenDictionary(df => df.Name.AsUnquoted(true, dbSetting), df => df, StringComparer.OrdinalIgnoreCase); private DbField GetPrimaryDbField() => dbFields.FirstOrDefault(df => df.IsPrimary); diff --git a/RepoDb.Core/RepoDb/RepoDb.csproj b/RepoDb.Core/RepoDb/RepoDb.csproj index 73ba09b1b..b1985ed7c 100644 --- a/RepoDb.Core/RepoDb/RepoDb.csproj +++ b/RepoDb.Core/RepoDb/RepoDb.csproj @@ -39,6 +39,10 @@ + + + + True