diff --git a/EntityRepository/EntityRepository.csproj b/EntityRepository/EntityRepository.csproj index 9a69648..bcd5028 100644 --- a/EntityRepository/EntityRepository.csproj +++ b/EntityRepository/EntityRepository.csproj @@ -1,9 +1,9 @@ - net7.0 + net8.0 Sidekick.EntityRepository - 3.1.0 + 4.0.0 Gustavo da Silva Oliveira sogustavo true @@ -15,10 +15,18 @@ MIT git + README.md - + + + + + + True + \ + diff --git a/EntityRepository/Interfaces.cs b/EntityRepository/Interfaces.cs index 5d6941b..83cdf5e 100644 --- a/EntityRepository/Interfaces.cs +++ b/EntityRepository/Interfaces.cs @@ -14,7 +14,7 @@ public interface IRead where T : class Task EntityAsync(Expression> predicate = null, params string[] includes); - List Entities(Expression> predicate = null, params string[] includes); + IEnumerable Entities(Expression> predicate = null, params string[] includes); Task> EntitiesAsync(Expression> predicate = null, params string[] includes); diff --git a/EntityRepository/Repository.cs b/EntityRepository/Repository.cs index 76bd943..753105a 100644 --- a/EntityRepository/Repository.cs +++ b/EntityRepository/Repository.cs @@ -8,24 +8,17 @@ namespace GenericRepository { - public class Repository : IRepository where T : class + public class Repository(DbContext context) : IRepository where T : class { - public readonly DbContext Context; + public readonly DbContext Context = context; - private readonly DbSet _table; - - public Repository(DbContext context) - { - Context = context; - - _table = context.Set(); - } + private readonly DbSet _table = context.Set(); public virtual T Entity(Expression> predicate = null, params string[] includes) { IQueryable query = Queryable(includes); - if (predicate != null) + if (predicate is not null) { return query.FirstOrDefault(predicate); } @@ -37,7 +30,7 @@ public virtual async Task EntityAsync(Expression> predicate = n { IQueryable query = Queryable(includes); - if (predicate != null) + if (predicate is not null) { return await query.FirstOrDefaultAsync(predicate); } @@ -45,11 +38,11 @@ public virtual async Task EntityAsync(Expression> predicate = n return await query.FirstOrDefaultAsync(); } - public virtual List Entities(Expression> predicate = null, params string[] includes) + public virtual IEnumerable Entities(Expression> predicate = null, params string[] includes) { IQueryable query = Queryable(includes); - if (predicate != null) + if (predicate is not null) { return query.Where(predicate).ToList(); } @@ -57,23 +50,23 @@ public virtual List Entities(Expression> predicate = null, para return query.ToList(); } - public virtual async Task> EntitiesAsync(Expression> predicate = null, params string[] includes) + public virtual Task> EntitiesAsync(Expression> predicate = null, params string[] includes) { IQueryable query = Queryable(includes); - if (predicate != null) + if (predicate is not null) { - return query.Where(predicate).ToList(); + return query.Where(predicate).ToListAsync(); } - return await query.ToListAsync(); + return query.ToListAsync(); } public virtual int Count(Expression> predicate = null, params string[] includes) { IQueryable query = Queryable(includes); - if (predicate != null) + if (predicate is not null) { return query.Count(predicate); } @@ -81,16 +74,16 @@ public virtual int Count(Expression> predicate = null, params stri return query.Count(); } - public virtual async Task CountAsync(Expression> predicate = null, params string[] includes) + public virtual Task CountAsync(Expression> predicate = null, params string[] includes) { IQueryable query = Queryable(includes); - if (predicate != null) + if (predicate is not null) { - return await query.CountAsync(predicate); + return query.CountAsync(predicate); } - return await query.CountAsync(); + return query.CountAsync(); } public virtual decimal Sum(Expression> selector, params string[] includes) @@ -100,11 +93,11 @@ public virtual decimal Sum(Expression> selector, params string[ return query.Sum(selector); } - public virtual async Task SumAsync(Expression> selector = null, params string[] includes) + public virtual Task SumAsync(Expression> selector = null, params string[] includes) { IQueryable query = Queryable(includes); - return await query.SumAsync(selector); + return query.SumAsync(selector); } public virtual bool Add(T entity) @@ -183,7 +176,7 @@ private IQueryable Queryable(params string[] includes) { IQueryable query = _table.AsQueryable(); - if (includes != null) + if (includes is not null) { for (int i = 0; i < includes.Length; i++) { diff --git a/ExtensionMethods/EnumerationExtension.cs b/ExtensionMethods/EnumerationExtension.cs index d0bb705..466be63 100644 --- a/ExtensionMethods/EnumerationExtension.cs +++ b/ExtensionMethods/EnumerationExtension.cs @@ -15,7 +15,7 @@ public static string Description(this Enum enumeration) } catch (Exception) { - return enumeration.ToString(); + return nameof(enumeration); } } } diff --git a/ExtensionMethods/ExtensionMethods.csproj b/ExtensionMethods/ExtensionMethods.csproj index 68e966a..07a44fc 100644 --- a/ExtensionMethods/ExtensionMethods.csproj +++ b/ExtensionMethods/ExtensionMethods.csproj @@ -1,9 +1,9 @@ - net7.0 + net8.0 Sidekick.ExtensionMethods - 3.2.0 + 4.0.0 Gustavo da Silva Oliveira sogustavo true @@ -14,6 +14,8 @@ https://github.com/sogustavo/sidekick extension-methods extensionmethods MIT + README.md + git @@ -21,4 +23,11 @@ + + + True + \ + + + diff --git a/ExtensionMethods/StringExtension.cs b/ExtensionMethods/StringExtension.cs index a234f87..220a6dc 100644 --- a/ExtensionMethods/StringExtension.cs +++ b/ExtensionMethods/StringExtension.cs @@ -42,26 +42,24 @@ public static bool IsCNPJ(this string text) return false; } - int[] multiplier1 = new int[12] { 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 }; + int[] multiplier1 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; - int[] multiplier2 = new int[13] { 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 }; - - int sum = 0, rest; - - string digit, CNPJ; + int[] multiplier2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; text = text.Trim(); text = text.Remove(".", "-", "/"); - CNPJ = text.Substring(0, 12); + var cnpj = text[..12]; + + var sum = 0; for (int i = 0; i < 12; i++) { - sum += int.Parse(CNPJ[i].ToString()) * multiplier1[i]; + sum += int.Parse(cnpj[i].ToString()) * multiplier1[i]; } - rest = sum % 11; + var rest = sum % 11; if (rest < 2) { @@ -72,15 +70,15 @@ public static bool IsCNPJ(this string text) rest = 11 - rest; } - digit = rest.ToString(); + var digit = rest.ToString(); - CNPJ = CNPJ + digit; + cnpj += digit; sum = 0; for (int i = 0; i < 13; i++) { - sum += int.Parse(CNPJ[i].ToString()) * multiplier2[i]; + sum += int.Parse(cnpj[i].ToString()) * multiplier2[i]; } rest = (sum % 11); @@ -94,7 +92,7 @@ public static bool IsCNPJ(this string text) rest = 11 - rest; } - digit = digit + rest.ToString(); + digit += rest.ToString(); return text.EndsWith(digit); } @@ -106,26 +104,24 @@ public static bool IsCPF(this string text) return false; } - int[] multiplier1 = new int[9] { 10, 9, 8, 7, 6, 5, 4, 3, 2 }; - - int[] multiplier2 = new int[10] { 11, 10, 9, 8, 7, 6, 5, 4, 3, 2 }; - - string CPF, digit; + int[] multiplier1 = [10, 9, 8, 7, 6, 5, 4, 3, 2]; - int sum = 0, rest; + int[] multiplier2 = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2]; text = text.Trim(); text = text.Remove(".", "-"); - CPF = text.Substring(0, 9); + var cpf = text[..9]; + + var sum = 0; for (int i = 0; i < 9; i++) { - sum += int.Parse(CPF[i].ToString()) * multiplier1[i]; + sum += int.Parse(cpf[i].ToString()) * multiplier1[i]; } - rest = sum % 11; + var rest = sum % 11; if (rest < 2) { @@ -136,15 +132,15 @@ public static bool IsCPF(this string text) rest = 11 - rest; } - digit = rest.ToString(); + var digit = rest.ToString(); - CPF = CPF + digit; + cpf += digit; sum = 0; for (int i = 0; i < 10; i++) { - sum += int.Parse(CPF[i].ToString()) * multiplier2[i]; + sum += int.Parse(cpf[i].ToString()) * multiplier2[i]; } rest = sum % 11; @@ -158,7 +154,7 @@ public static bool IsCPF(this string text) rest = 11 - rest; } - digit = digit + rest.ToString(); + digit += rest.ToString(); return text.EndsWith(digit); } @@ -170,22 +166,20 @@ public static bool IsPIS(this string text) return false; } - int[] multiplier = new int[10] { 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 }; - - int sum = 0, rest; + int[] multiplier = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; text = text.Trim(); text = text.Remove("-", ".").PadLeft(11, '0'); - sum = 0; + var sum = 0; for (int i = 0; i < 10; i++) { sum += int.Parse(text[i].ToString()) * multiplier[i]; } - rest = sum % 11; + var rest = sum % 11; if (rest < 2) { @@ -201,7 +195,7 @@ public static bool IsPIS(this string text) public static string AssemblyPath(this Assembly assembly) { - return new Uri(assembly.CodeBase).LocalPath; + return new Uri(assembly.Location).LocalPath; } public static string Extension(this string filename) diff --git a/ExtensionMethods/TryParseExtension.cs b/ExtensionMethods/TryParseExtension.cs index fc6b5e6..20f8989 100644 --- a/ExtensionMethods/TryParseExtension.cs +++ b/ExtensionMethods/TryParseExtension.cs @@ -7,7 +7,7 @@ public static class TryParseExtension { public static T? TryParse(this object obj) where T : struct { - if (obj == null) + if (obj is null) { return null; } @@ -16,11 +16,11 @@ public static class TryParseExtension TypeConverter tc = TypeDescriptor.GetConverter(typeof(T)); - if (tc != null) + if (tc is not null) { try { - string value = obj.ToString(); + var value = obj.ToString(); result = (T)tc.ConvertFromString(value); } diff --git a/Sidekick.sln b/Sidekick.sln index b9057d4..5a368b9 100644 --- a/Sidekick.sln +++ b/Sidekick.sln @@ -1,12 +1,25 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27428.2043 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34511.84 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExtensionMethods", "ExtensionMethods\ExtensionMethods.csproj", "{4F0DA7F3-B797-46C3-A557-693D7DBA371F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityRepository", "EntityRepository\EntityRepository.csproj", "{D1C2FDF9-AEB6-4963-8FDD-BC3CDD305BE9}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4D175A66-80CC-4D27-ABC8-91116D03B656}" + ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore + global.json = global.json + LICENSE = LICENSE + README.md = README.md + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{3B345ABD-7D2E-443A-9D01-84664C4CD269}" + ProjectSection(SolutionItems) = preProject + Docs\sidekick.gif = Docs\sidekick.gif + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -25,6 +38,9 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {3B345ABD-7D2E-443A-9D01-84664C4CD269} = {4D175A66-80CC-4D27-ABC8-91116D03B656} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {85D56564-5B95-45C1-91E9-E16F8A347988} EndGlobalSection diff --git a/global.json b/global.json index 1621e25..e149a34 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { - "sdk": { - "version": "7.0.101", - "rollForward": "latestFeature", - "allowPrerelease": false - } -} \ No newline at end of file + "sdk": { + "version": "8.0.101", + "rollForward": "latestFeature", + "allowPrerelease": false + } +}