diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index 58753a8..578545e 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -7,7 +7,7 @@ on:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- - cron: '0 9 * * 5'
+ - cron: "0 9 * * 5"
jobs:
analyze:
@@ -19,39 +19,57 @@ jobs:
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
- language: ['csharp']
+ language: ["csharp"]
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
steps:
- - name: Checkout repository
- uses: actions/checkout@v2
- with:
- # We must fetch at least the immediate parents so that if this is
- # a pull request then we can checkout the head.
- fetch-depth: 2
-
- # Initializes the CodeQL tools for scanning.
- - name: Initialize CodeQL
- uses: github/codeql-action/init@v1
- with:
- languages: ${{ matrix.language }}
-
- # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
- # If this step fails, then you should remove it and run the build manually (see below)
- - name: Autobuild
- uses: github/codeql-action/autobuild@v1
-
- # ℹ️ Command-line programs to run using the OS shell.
- # 📚 https://git.io/JvXDl
-
- # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
- # and modify them (or add more) to build your code if your project
- # uses a compiled language
-
- #- run: |
- # make bootstrap
- # make release
-
- - name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@v1
+ - name: Checkout repository
+ uses: actions/checkout@v2
+ with:
+ # We must fetch at least the immediate parents so that if this is
+ # a pull request then we can checkout the head.
+ fetch-depth: 2
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v1
+ with:
+ languages: ${{ matrix.language }}
+
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
+ # If this step fails, then you should remove it and run the build manually (see below)
+ # - name: Autobuild
+ # uses: github/codeql-action/autobuild@v1
+
+ # ℹ️ Command-line programs to run using the OS shell.
+ # 📚 https://git.io/JvXDl
+
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
+ # and modify them (or add more) to build your code if your project
+ # uses a compiled language
+
+ #- run: |
+ # make bootstrap
+ # make release
+ - name: Setup .NET 5
+ uses: actions/setup-dotnet@v1
+ with:
+ dotnet-version: 5.0.x
+
+ - name: Setup .NET 6
+ uses: actions/setup-dotnet@v1
+ with:
+ dotnet-version: 6.0.x
+
+ - name: Install dependencies
+ run: cd src && dotnet restore
+
+ - name: .Net Version
+ run: cd src && dotnet --version
+
+ - name: Build
+ run: cd src && dotnet build --configuration Release --no-restore
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v1
diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml
index 9c61039..ce3685d 100644
--- a/.github/workflows/dotnet-core.yml
+++ b/.github/workflows/dotnet-core.yml
@@ -2,45 +2,54 @@ name: .NET Core
on:
push:
- branches: [ master ]
+ branches: [master]
pull_request:
- branches: [ master ]
+ branches: [master]
jobs:
build:
-
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
- - name: Setup .NET Core
- uses: actions/setup-dotnet@v1
- with:
- dotnet-version: 3.1.405
-
- - name: Install dependencies
- run: cd src && dotnet restore
-
- - name: Build
- run: cd src && dotnet build --configuration Release --no-restore
-
- - name: Linting code with dotnet-format
- run: cd src && ./run-dotnet-format.sh
-
- - name: Test
- run: cd src && ./codeclimate_code_coverage.sh
- env:
- CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
-
- - name: docfx-action
- uses: nikeee/docfx-action@v1.0.0
- with:
- args: docs/docfx.json
-
- - name: Update Library DocFx documentation
- run: cd src && ./release-docfx-github.sh
- env:
- BYTEDECODER_COMMON_GITHUB_CI_ACTIONS: ${{ secrets.BYTEDECODER_COMMON_GITHUB_CI_ACTIONS }}
- DOCFX_GITHUB_EMAIL: ${{ secrets.DOCFX_GITHUB_EMAIL }}
+ - uses: actions/checkout@v2
+
+ - name: Setup .NET 5
+ uses: actions/setup-dotnet@v1
+ with:
+ dotnet-version: 5.0.x
+
+ - name: Setup .NET 6
+ uses: actions/setup-dotnet@v1
+ with:
+ dotnet-version: 6.0.x
+
+ - name: Install dependencies
+ run: cd src && dotnet restore
+
+ - name: .Net Version
+ run: cd src && dotnet --version
+
+ - name: Build
+ run: cd src && dotnet build --configuration Release --no-restore
+
+ - name: Security Code Scan
+ run: cd src && ./run-security-code-scan.sh
+
+ - name: Linting code with dotnet-format
+ run: cd src && ./run-dotnet-format.sh
+
+ - name: Test
+ run: cd src && ./codeclimate_code_coverage.sh
+ env:
+ CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
+ - name: docfx-action
+ uses: nikeee/docfx-action@v1.0.0
+ with:
+ args: docs/docfx.json
+ - name: Update Library DocFx documentation
+ run: cd src && ./release-docfx-github.sh
+ env:
+ BYTEDECODER_COMMON_GITHUB_CI_ACTIONS: ${{ secrets.BYTEDECODER_COMMON_GITHUB_CI_ACTIONS }}
+ DOCFX_GITHUB_EMAIL: ${{ secrets.DOCFX_GITHUB_EMAIL }}
diff --git a/CHANGELOG b/CHANGELOG
index 6bcc438..9016578 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,38 +1,60 @@
+# Changelog
+
+## Version Changes
+
+### 1.0.0 - 2022-01-02
+
+- C# 10 adopted
+- .Net Standard support deprecated
+- Support from .Net6 onwards
+- New CSA tools added into the build pipeline
+
### 0.3.6 - 2021-01-25
- * Added ToCamelCase string extension methods.
+
+- Added ToCamelCase string extension methods.
### 0.3.5 - 2021-01-20
- * Added ToEnum string extension methods.
- * Added DateTimeOffset extensions methods.
+
+- Added ToEnum string extension methods.
+- Added DateTimeOffset extensions methods.
### 0.3.4 - 2020-08-19
- * Transparent favicon added
+
+- Transparent favicon added
### 0.3.3 - 2020-08-19
- * Library logos added in the DocFX documentation
-
+
+- Library logos added in the DocFX documentation
+
### 0.3.2 - 2020-08-18
- * DocFX documentation completed
- * Official documentation url https://bytedecoder.me/ByteDecoder.Common/
-
+
+- DocFX documentation completed
+- Official documentation url
+
### 0.3.1 - 2020-08-13
- * Guard interface implementation refactored
- * StyleCop and FxCop analyzers added as part of the development workflow
- * Violating the analyzers rules will throw errors on compile, until they are fix
- * All methods, classes and interfaces consumables for third parties in the Library has now documentation
+
+- Guard interface implementation refactored
+- StyleCop and FxCop analyzers added as part of the development workflow
+- Violating the analyzers rules will throw errors on compile, until they are fix
+- All methods, classes and interfaces consumables for third parties in the Library has now documentation
### 0.3.0 - 2020-07-29
- * Added MathComparisonExtensions extensions methods for math comparisions
- * Added IfArgumentOutOfRange Guard clause
+
+- Added MathComparisonExtensions extensions methods for math comparisions
+- Added IfArgumentOutOfRange Guard clause
### 0.2.3 - 2020-07-28
- * Fixed problem with Possible multiple enumeration of IEnumerable using with Resharper with JETBRAINS_ANNOTATIONS compilation symbol
+
+- Fixed problem with Possible multiple enumeration of IEnumerable using with Resharper with JETBRAINS_ANNOTATIONS compilation symbol
### 0.2.1 - 2020-07-28
- * Added AllowedOutputExtensionsInPackageBuildOutputFolder in ByteDecoder.Common project
+
+- Added AllowedOutputExtensionsInPackageBuildOutputFolder in ByteDecoder.Common project
### 0.2.0 - 2020-07-27
- * Added Jetbrains Annotations for avoding false positive: Possible multiple enumeration of IEnumerable
+
+- Added Jetbrains Annotations for avoding false positive: Possible multiple enumeration of IEnumerable
### 0.1.0 - 2020-07-27
- * Initial release
+
+- Initial release
diff --git a/README.md b/README.md
index 303e040..d151c3b 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@
Common utility classes, guard clauses, and more.
-Targeted to .Net Standard 2.0
+Targeted to .Net6 onwards
## Installation
@@ -36,7 +36,7 @@ All the documentation can be found on the [github page](https://bytedecoder.me/B
They are a piece of code in charge of protecting params at the top of methods against undesirable values.
-Supported *Guard Clauses*:
+Supported _Guard Clauses_:
- IfArgumentIsNull
- IfArgumentIsNullOrEmpty
@@ -51,7 +51,7 @@ using ByteDecoder.Common.GuardClauses;
public void MethodOne(IEnumerable collection)
{
Guard.Break.IfArgumentIsNull(collection, nameof(collection));
-
+
// More logic code if the param is suitable after the guard evaluates the condition.
}
@@ -59,7 +59,7 @@ public void MethodOne(IEnumerable collection)
public void MethodTwo(string word)
{
Guard.Break.IfArgumentIsNull(word, nameof(word));
-
+
// More logic code if the param is suitable after the guard evaluates the condition.
}
diff --git a/src/.config/dotnet-tools.json b/src/.config/dotnet-tools.json
new file mode 100644
index 0000000..06c34e9
--- /dev/null
+++ b/src/.config/dotnet-tools.json
@@ -0,0 +1,14 @@
+{
+ "version": 1,
+ "isRoot": true,
+ "tools": {
+ "security-scan": {
+ "version": "5.6.0",
+ "commands": ["security-scan"]
+ },
+ "dotnet-format": {
+ "version": "5.1.250801",
+ "commands": ["dotnet-format"]
+ }
+ }
+}
diff --git a/src/ByteDecoder.Common.Tests/ByteDecoder.Common.Tests.csproj b/src/ByteDecoder.Common.Tests/ByteDecoder.Common.Tests.csproj
index 5a468d1..52087ed 100644
--- a/src/ByteDecoder.Common.Tests/ByteDecoder.Common.Tests.csproj
+++ b/src/ByteDecoder.Common.Tests/ByteDecoder.Common.Tests.csproj
@@ -1,44 +1,42 @@
-
+
- netcoreapp3.1
+ net6.0
+ enable
false
+
+ $(SolutionDir)\_stylecop\TestProjStyleCopRules.ruleset
+
+
+ True
+
+ 1701;1702;1705
+
-
-
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
all
+
-
+
-
-
+
-
-
- $(SolutionDir)\_stylecop\TestProjStyleCopRules.ruleset
-
-
-
- True
-
- 1701;1702;1705
+
+ AllEnabledByDefault
-
\ No newline at end of file
diff --git a/src/ByteDecoder.Common.Tests/GuardTests.cs b/src/ByteDecoder.Common.Tests/GuardTests.cs
index 14fd8ac..5b70c1c 100644
--- a/src/ByteDecoder.Common.Tests/GuardTests.cs
+++ b/src/ByteDecoder.Common.Tests/GuardTests.cs
@@ -21,7 +21,7 @@ public void ThrowIfArgumentIsNull_ThrowsNullArgumentException_WhenSourceIsNull()
// Act
var exception = Record.Exception(() =>
{
- Guard.Break.IfArgumentIsNull((IEnumerable)null, "collection");
+ Guard.Break.IfArgumentIsNull?>(null, "collection");
});
// Assert
@@ -49,7 +49,7 @@ public void ThrowIfArgumentIsNullWithMessage_ThrowsNullArgumentException_WhenSou
// Act
var exception = Record.Exception(() =>
{
- Guard.Break.IfArgumentIsNull((IEnumerable)null, "collection", "An error occurred");
+ Guard.Break.IfArgumentIsNull((IEnumerable?)null, "collection", "An error occurred");
});
// Assert
diff --git a/src/ByteDecoder.Common.sln b/src/ByteDecoder.Common.sln
index 1f23616..ed08026 100644
--- a/src/ByteDecoder.Common.sln
+++ b/src/ByteDecoder.Common.sln
@@ -1,8 +1,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.26124.0
-MinimumVisualStudioVersion = 15.0.26124.0
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30114.105
+MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ByteDecoder.Common", "ByteDecoder.Common\ByteDecoder.Common.csproj", "{8E47AA9F-A9AE-4104-B3EF-DDEC366C9D94}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ByteDecoder.Common.Tests", "ByteDecoder.Common.Tests\ByteDecoder.Common.Tests.csproj", "{127AD73D-0572-4D6E-9EF2-23909C5A84E3}"
diff --git a/src/ByteDecoder.Common/ByteDecoder.Common.cs b/src/ByteDecoder.Common/ByteDecoder.Common.cs
new file mode 100644
index 0000000..5de3ebe
--- /dev/null
+++ b/src/ByteDecoder.Common/ByteDecoder.Common.cs
@@ -0,0 +1,6 @@
+#pragma warning disable SA1516
+
+[assembly: CLSCompliant(true)]
+namespace ByteDecoder.Common;
+
+#pragma warning restore SA1516
diff --git a/src/ByteDecoder.Common/ByteDecoder.Common.csproj b/src/ByteDecoder.Common/ByteDecoder.Common.csproj
index 45ac444..a1e99ac 100644
--- a/src/ByteDecoder.Common/ByteDecoder.Common.csproj
+++ b/src/ByteDecoder.Common/ByteDecoder.Common.csproj
@@ -1,12 +1,15 @@
-
+
- netstandard2.0
+ net6.0
+ enable
+ enable
+
- netstandard2.0
+ net6.0
ByteDecoder.Common
ByteDecoder
-
+
ByteDecoder.Common
ByteDecoder.Common
Common utility classes
@@ -24,39 +27,49 @@
Common utility classes
$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
+
TRACE;JETBRAINS_ANNOTATIONS
-
True
-
+
1701;1702;1705
bin\Debug\netstandard2.0\ByteDecoder.Common.xml
+
+
+ $(SolutionDir)\_stylecop\LibraryStyleCopRules.ruleset
+
+
True
-
+
+
-
-
+
+
all
-
+
all
+
+ all
+
+
+
+
+ AllEnabledByDefault
+
+
-
+
-
+
-
-
- $(SolutionDir)\_stylecop\LibraryStyleCopRules.ruleset
-
-
\ No newline at end of file
diff --git a/src/ByteDecoder.Common/DateTimeOffsetExtensions.cs b/src/ByteDecoder.Common/DateTimeOffsetExtensions.cs
index c118291..ce19826 100644
--- a/src/ByteDecoder.Common/DateTimeOffsetExtensions.cs
+++ b/src/ByteDecoder.Common/DateTimeOffsetExtensions.cs
@@ -1,27 +1,24 @@
-using System;
+namespace ByteDecoder.Common;
-namespace ByteDecoder.Common
+///
+/// DateTimeOffset extensions.
+///
+public static class DateTimeOffsetExtensions
{
///
- /// DateTimeOffset extensions.
+ /// Extend a contract based in a number of months to the last day of the month.
///
- public static class DateTimeOffsetExtensions
+ /// Current date to extend.
+ /// Month number extension.
+ /// New extended DateTimeOffset.
+ public static DateTimeOffset ExtendContract(this DateTimeOffset current, int months)
{
- ///
- /// Extend a contract based in a number of months to the last day of the month.
- ///
- /// Current date to extend.
- /// Month number extension.
- /// New extended DateTimeOffset.
- public static DateTimeOffset ExtendContract(this DateTimeOffset current, int months)
- {
- var newContractDate = current.AddMonths(months).AddTicks(-1);
+ var newContractDate = current.AddMonths(months).AddTicks(-1);
- return new DateTimeOffset(
- newContractDate.Year,
- newContractDate.Month,
- DateTime.DaysInMonth(newContractDate.Year, newContractDate.Month),
- 23, 59, 59, current.Offset);
- }
+ return new DateTimeOffset(
+ newContractDate.Year,
+ newContractDate.Month,
+ DateTime.DaysInMonth(newContractDate.Year, newContractDate.Month),
+ 23, 59, 59, current.Offset);
}
}
diff --git a/src/ByteDecoder.Common/EnumExtensions.cs b/src/ByteDecoder.Common/EnumExtensions.cs
index e15cecd..6ab10b7 100644
--- a/src/ByteDecoder.Common/EnumExtensions.cs
+++ b/src/ByteDecoder.Common/EnumExtensions.cs
@@ -1,38 +1,35 @@
-using System;
+namespace ByteDecoder.Common;
-namespace ByteDecoder.Common
+///
+/// Enum type extensions.
+///
+public static class EnumExtensions
{
///
- /// Enum type extensions.
+ /// Converts a string value to an Enum value.
///
- public static class EnumExtensions
+ /// Enum type.
+ /// Value to convert.
+ /// Enum value.
+ public static T ToEnum(this string value) where T : struct
{
- ///
- /// Converts a string value to an Enum value.
- ///
- /// Enum type.
- /// Value to convert.
- /// Enum value.
- public static T ToEnum(this string value) where T : struct, IConvertible
- {
- return (T)Enum.Parse(typeof(T), value, true);
- }
+ return (T)Enum.Parse(typeof(T), value, true);
+ }
- ///
- /// Converts a string value to an Enum value, if fails returns the default value
- /// specified.
- ///
- /// Enum type.
- /// Value to convert.
- /// Default enum value.
- /// Enum value.
- public static T ToEnum(this string value, T defaultValue) where T : struct, IConvertible
- {
- if (string.IsNullOrWhiteSpace(value))
- return defaultValue;
+ ///
+ /// Converts a string value to an Enum value, if fails returns the default value
+ /// specified.
+ ///
+ /// Enum type.
+ /// Value to convert.
+ /// Default enum value.
+ /// Enum value.
+ public static T ToEnum(this string value, T defaultValue) where T : struct
+ {
+ if (string.IsNullOrWhiteSpace(value))
+ return defaultValue;
- T result;
- return Enum.TryParse(value, true, out result) ? result : defaultValue;
- }
+ T result;
+ return Enum.TryParse(value, true, out result) ? result : defaultValue;
}
}
diff --git a/src/ByteDecoder.Common/GuardClauses/Guard.cs b/src/ByteDecoder.Common/GuardClauses/Guard.cs
index e5e3950..dccfb46 100644
--- a/src/ByteDecoder.Common/GuardClauses/Guard.cs
+++ b/src/ByteDecoder.Common/GuardClauses/Guard.cs
@@ -1,81 +1,82 @@
-using System;
-using JetBrains.Annotations;
+using JetBrains.Annotations;
-namespace ByteDecoder.Common.GuardClauses
+namespace ByteDecoder.Common.GuardClauses;
+
+///
+/// Guard singleton class.
+///
+public class Guard : IGuardClause
{
+ private Guard() { }
+
///
- /// Guard singleton class.
+ /// Gets the Guard instance.
///
- public class Guard : IGuardClause
- {
- private Guard() { }
+ /// Guard extension methods.
+ public static IGuardClause Break { get; } = new Guard();
- ///
- /// Gets the Guard instance.
- ///
- /// Guard extension methods.
- public static IGuardClause Break { get; } = new Guard();
-
- ///
- /// Guard and check a value if is not null.
- ///
- /// Generic type for the guard.
- /// Instance source.
- /// Param name.
- public void IfArgumentIsNull([NoEnumeration][ValidatedNotNull] T source, string paramName) where T : class
- {
- if (source == null)
- throw new ArgumentNullException(paramName);
- }
+ ///
+ /// Guard and check a value if is not null.
+ ///
+ /// Generic type for the guard.
+ /// Instance source.
+ /// Param name.
+ public void IfArgumentIsNull([NoEnumeration][ValidatedNotNull] T source, string paramName)
+ {
+ if (source == null)
+ throw new ArgumentNullException(paramName);
+ }
- ///
- /// Guard and check a value if is not null.
- ///
- /// Generic type for the guard.
- /// Instance source.
- /// Param name.
- /// Message if guard clause breaks.
- public void IfArgumentIsNull([NoEnumeration][ValidatedNotNull] T source, string paramName, string message) where T : class
- {
- if (source == null)
- throw new ArgumentNullException(paramName, message);
- }
+ ///
+ /// Guard and check a value if is not null.
+ ///
+ /// Generic type for the guard.
+ /// Instance source.
+ /// Param name.
+ /// Message if guard clause breaks.
+ public void IfArgumentIsNull(
+ [NoEnumeration][ValidatedNotNull] T source,
+ string paramName,
+ string message)
+ {
+ if (source == null)
+ throw new ArgumentNullException(paramName, message);
+ }
- ///
- /// Guard and check a value if is not null or neither empty.
- ///
- /// Instance source.
- /// Param name.
- public void IfArgumentIsNullOrEmpty(string source, string paramName)
- {
- if (string.IsNullOrEmpty(source))
- throw new ArgumentNullException(paramName);
- }
+ ///
+ /// Guard and check a value if is not null or neither empty.
+ ///
+ /// Instance source.
+ /// Param name.
+ public void IfArgumentIsNullOrEmpty(string? source, string paramName)
+ {
+ if (string.IsNullOrEmpty(source))
+ throw new ArgumentNullException(paramName);
+ }
- ///
- /// Guard and check a value if is not null or neither empty.
- ///
- /// Instance source.
- /// Param name.
- /// Message if guard clause breaks.
- public void IfArgumentIsNullOrEmpty(string source, string paramName, string message)
- {
- if (string.IsNullOrEmpty(source))
- throw new ArgumentNullException(paramName, message);
- }
+ ///
+ /// Guard and check a value if is not null or neither empty.
+ ///
+ /// Instance source.
+ /// Param name.
+ /// Message if guard clause breaks.
+ public void IfArgumentIsNullOrEmpty(string? source, string paramName, string message)
+ {
+ if (string.IsNullOrEmpty(source))
+ throw new ArgumentNullException(paramName, message);
+ }
- ///
- /// Guard and check a value if is in a range.
- ///
- /// Predicate that evaluates the range.
- /// Param name.
- /// Message if guard clause breaks.
- public void IfArgumentOutOfRange(Func predicate, string paramName, string message)
- {
- IfArgumentIsNull(predicate, nameof(predicate));
+ ///
+ /// Guard and check a value if is in a range.
+ ///
+ /// Predicate that evaluates the range.
+ /// Param name.
+ /// Message if guard clause breaks.
+ public void IfArgumentOutOfRange(Func predicate, string paramName, string message)
+ {
+ IfArgumentIsNull(predicate, nameof(predicate));
- if (predicate())
- throw new ArgumentOutOfRangeException(paramName, message);
- }
+ if (predicate())
+ throw new ArgumentOutOfRangeException(paramName, message);
}
}
diff --git a/src/ByteDecoder.Common/GuardClauses/IGuardClause.cs b/src/ByteDecoder.Common/GuardClauses/IGuardClause.cs
index 8f0f544..9c07f6b 100644
--- a/src/ByteDecoder.Common/GuardClauses/IGuardClause.cs
+++ b/src/ByteDecoder.Common/GuardClauses/IGuardClause.cs
@@ -1,51 +1,52 @@
-using System;
-using JetBrains.Annotations;
+using JetBrains.Annotations;
-namespace ByteDecoder.Common.GuardClauses
+namespace ByteDecoder.Common.GuardClauses;
+
+///
+/// Interface for extending the guard clauses using extensions methods.
+///
+public interface IGuardClause
{
///
- /// Interface for extending the guard clauses using extensions methods.
+ /// Guard and check a value if is not null.
///
- public interface IGuardClause
- {
- ///
- /// Guard and check a value if is not null.
- ///
- /// Generic type for the guard.
- /// Instance source.
- /// Param name.
- void IfArgumentIsNull([NoEnumeration][ValidatedNotNull] T source, string paramName) where T : class;
+ /// Generic type for the guard.
+ /// Instance source.
+ /// Param name.
+ void IfArgumentIsNull([NoEnumeration][ValidatedNotNull] T source, string paramName);
- ///
- /// Guard and check a value if is not null.
- ///
- /// Generic type for the guard.
- /// Instance source.
- /// Param name.
- /// Message if guard clause breaks.
- void IfArgumentIsNull([NoEnumeration][ValidatedNotNull] T source, string paramName, string message) where T : class;
+ ///
+ /// Guard and check a value if is not null.
+ ///
+ /// Generic type for the guard.
+ /// Instance source.
+ /// Param name.
+ /// Message if guard clause breaks.
+ void IfArgumentIsNull(
+ [NoEnumeration][ValidatedNotNull] T source,
+ string paramName,
+ string message);
- ///
- /// Guard and check a value if is not null or neither empty.
- ///
- /// Instance source.
- /// Param name.
- void IfArgumentIsNullOrEmpty(string source, string paramName);
+ ///
+ /// Guard and check a value if is not null or neither empty.
+ ///
+ /// Instance source.
+ /// Param name.
+ void IfArgumentIsNullOrEmpty(string? source, string paramName);
- ///
- /// Guard and check a value if is not null or neither empty.
- ///
- /// Instance source.
- /// Param name.
- /// Message if guard clause breaks.
- void IfArgumentIsNullOrEmpty(string source, string paramName, string message);
+ ///
+ /// Guard and check a value if is not null or neither empty.
+ ///
+ /// Instance source.
+ /// Param name.
+ /// Message if guard clause breaks.
+ void IfArgumentIsNullOrEmpty(string? source, string paramName, string message);
- ///
- /// Guard and check a value if is in a range.
- ///
- /// Predicate that evaluates the range.
- /// Param name.
- /// Message if guard clause breaks.
- void IfArgumentOutOfRange(Func predicate, string paramName, string message);
- }
+ ///
+ /// Guard and check a value if is in a range.
+ ///
+ /// Predicate that evaluates the range.
+ /// Param name.
+ /// Message if guard clause breaks.
+ void IfArgumentOutOfRange(Func predicate, string paramName, string message);
}
diff --git a/src/ByteDecoder.Common/GuardClauses/ValidatedNotNullAttribute.cs b/src/ByteDecoder.Common/GuardClauses/ValidatedNotNullAttribute.cs
index 5054d25..01c02df 100644
--- a/src/ByteDecoder.Common/GuardClauses/ValidatedNotNullAttribute.cs
+++ b/src/ByteDecoder.Common/GuardClauses/ValidatedNotNullAttribute.cs
@@ -1,11 +1,8 @@
-using System;
+namespace ByteDecoder.Common.GuardClauses;
-namespace ByteDecoder.Common.GuardClauses
-{
- ///
- /// Indicates to Code Analysis that a method validates a particular parameter.
- /// https://docs.microsoft.com/en-us/dotnet/api/microsoft.validatednotnullattribute?view=visualstudiosdk-2019.
- ///
- [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
- public sealed class ValidatedNotNullAttribute : Attribute { }
-}
+///
+/// Indicates to Code Analysis that a method validates a particular parameter.
+/// https://docs.microsoft.com/en-us/dotnet/api/microsoft.validatednotnullattribute?view=visualstudiosdk-2019.
+///
+[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
+public sealed class ValidatedNotNullAttribute : Attribute { }
diff --git a/src/ByteDecoder.Common/MathComparisonExtensions.cs b/src/ByteDecoder.Common/MathComparisonExtensions.cs
index 9b2c211..702765b 100644
--- a/src/ByteDecoder.Common/MathComparisonExtensions.cs
+++ b/src/ByteDecoder.Common/MathComparisonExtensions.cs
@@ -1,56 +1,55 @@
-namespace ByteDecoder.Common
+namespace ByteDecoder.Common;
+
+///
+/// Integer math comparision extension methods.
+///
+public static class MathComparisonExtensions
{
///
- /// Integer math comparision extension methods.
+ /// Integer extension method for Greater Than.
///
- public static class MathComparisonExtensions
- {
- ///
- /// Integer extension method for Greater Than.
- ///
- /// Current integer source value.
- /// integer type to compare against it.
- /// Boolean evaluation result.
- public static bool IsGreaterThan(this int i, int value) => i > value;
+ /// Current integer source value.
+ /// integer type to compare against it.
+ /// Boolean evaluation result.
+ public static bool IsGreaterThan(this int i, int value) => i > value;
- ///
- /// Integer extension method for Less Than.
- ///
- /// Current integer source value.
- /// integer type to compare against it.
- /// Boolean evaluation result.
- public static bool IsLessThan(this int i, int value) => i < value;
+ ///
+ /// Integer extension method for Less Than.
+ ///
+ /// Current integer source value.
+ /// integer type to compare against it.
+ /// Boolean evaluation result.
+ public static bool IsLessThan(this int i, int value) => i < value;
- ///
- /// Integer extension method for Equal To.
- ///
- /// Current integer source value.
- /// integer type to compare against it.
- /// Boolean evaluation result.
- public static bool IsEqualTo(this int i, int value) => i == value;
+ ///
+ /// Integer extension method for Equal To.
+ ///
+ /// Current integer source value.
+ /// integer type to compare against it.
+ /// Boolean evaluation result.
+ public static bool IsEqualTo(this int i, int value) => i == value;
- ///
- /// Integer extension method for Not Equal To.
- ///
- /// Current integer source value.
- /// integer type to compare against it.
- /// Boolean evaluation result.
- public static bool IsNotEqualTo(this int i, int value) => i != value;
+ ///
+ /// Integer extension method for Not Equal To.
+ ///
+ /// Current integer source value.
+ /// integer type to compare against it.
+ /// Boolean evaluation result.
+ public static bool IsNotEqualTo(this int i, int value) => i != value;
- ///
- /// Integer extension method for Greater Than Or Equal To.
- ///
- /// Current integer source value.
- /// integer type to compare against it.
- /// Boolean evaluation result.
- public static bool IsGreaterThanOrEqualTo(this int i, int value) => i >= value;
+ ///
+ /// Integer extension method for Greater Than Or Equal To.
+ ///
+ /// Current integer source value.
+ /// integer type to compare against it.
+ /// Boolean evaluation result.
+ public static bool IsGreaterThanOrEqualTo(this int i, int value) => i >= value;
- ///
- /// Integer extension method for Less Than Or Equal To.
- ///
- /// Current integer source value.
- /// integer type to compare against it.
- /// Boolean evaluation result.
- public static bool IsLessThanOrEqualTo(this int i, int value) => i <= value;
- }
+ ///
+ /// Integer extension method for Less Than Or Equal To.
+ ///
+ /// Current integer source value.
+ /// integer type to compare against it.
+ /// Boolean evaluation result.
+ public static bool IsLessThanOrEqualTo(this int i, int value) => i <= value;
}
diff --git a/src/ByteDecoder.Common/NuGetDefense.json b/src/ByteDecoder.Common/NuGetDefense.json
new file mode 100644
index 0000000..0df7264
--- /dev/null
+++ b/src/ByteDecoder.Common/NuGetDefense.json
@@ -0,0 +1,33 @@
+{
+ "WarnOnly": false,
+ "VulnerabilityReports": {
+ "OutputTextReport": true
+ },
+ "CheckTransitiveDependencies": true,
+ "CheckReferencedProjects": false,
+ "ErrorSettings": {
+ "ErrorSeverityThreshold": "any",
+ "Cvss3Threshold": -1,
+ "IgnoredPackages": [
+ {
+ "Id": "NugetDefense"
+ }
+ ],
+ "IgnoredCvEs": [],
+ "AllowedPackages": [],
+ "BlockedPackages": []
+ },
+ "OssIndex": {
+ "ApiToken": "",
+ "Username": "",
+ "Enabled": true,
+ "BreakIfCannotRun": true
+ },
+ "NVD": {
+ "SelfUpdate": false,
+ "TimeoutInSeconds": 15,
+ "Enabled": true,
+ "BreakIfCannotRun": true
+ },
+ "SensitivePackages": []
+}
\ No newline at end of file
diff --git a/src/ByteDecoder.Common/StringExtensions.cs b/src/ByteDecoder.Common/StringExtensions.cs
index 1cabc8b..84dee02 100644
--- a/src/ByteDecoder.Common/StringExtensions.cs
+++ b/src/ByteDecoder.Common/StringExtensions.cs
@@ -1,53 +1,51 @@
-using System;
-using System.Globalization;
+using System.Globalization;
-namespace ByteDecoder.Common
+namespace ByteDecoder.Common;
+
+///
+/// String extensions methods.
+///
+public static class StringExtensions
{
///
- /// String extensions methods.
+ /// Convert a string to integer type.
///
- public static class StringExtensions
+ /// Source string.
+ /// Parse result.
+ public static int ToInt(this string source)
{
- ///
- /// Convert a string to integer type.
- ///
- /// Source string.
- /// Parse result.
- public static int ToInt(this string source)
+ return int.Parse(source, NumberFormatInfo.CurrentInfo);
+ }
+
+ ///
+ /// Convert a string to double type.
+ ///
+ /// Source string.
+ /// Parse result.
+ public static double ToDouble(this string source)
+ {
+ try
{
- return int.Parse(source, NumberFormatInfo.CurrentInfo);
+ return double.Parse(source, NumberFormatInfo.CurrentInfo);
}
-
- ///
- /// Convert a string to double type.
- ///
- /// Source string.
- /// Parse result.
- public static double ToDouble(this string source)
+ catch (FormatException)
{
- try
- {
- return double.Parse(source, NumberFormatInfo.CurrentInfo);
- }
- catch (FormatException)
- {
- return double.NaN;
- }
+ return double.NaN;
}
+ }
- ///
- /// Converts an string into a camelCase representation.
- ///
- /// Source string.
- /// Camel case string result.
- public static string ToCamelCase(this string source)
+ ///
+ /// Converts an string into a camelCase representation.
+ ///
+ /// Source string.
+ /// Camel case string result.
+ public static string ToCamelCase(this string source)
+ {
+ if (!string.IsNullOrEmpty(source) && source.Length > 1)
{
- if (!string.IsNullOrEmpty(source) && source.Length > 1)
- {
- return char.ToLowerInvariant(source[0]) + source.Substring(1);
- }
-
- return source;
+ return char.ToLowerInvariant(source[0]) + source.Substring(1);
}
+
+ return source;
}
}
diff --git a/src/_stylecop/TestProjStyleCopRules.ruleset b/src/_stylecop/TestProjStyleCopRules.ruleset
index 2c87ffc..493e6c9 100644
--- a/src/_stylecop/TestProjStyleCopRules.ruleset
+++ b/src/_stylecop/TestProjStyleCopRules.ruleset
@@ -3,6 +3,7 @@
+
diff --git a/src/global.json b/src/global.json
index d82f13f..e52d340 100644
--- a/src/global.json
+++ b/src/global.json
@@ -1,5 +1,5 @@
{
"sdk": {
- "version": "3.1.405"
+ "version": "6.0.101"
}
}
diff --git a/src/run-dotnet-format.sh b/src/run-dotnet-format.sh
index 9a62db9..0bb0c78 100755
--- a/src/run-dotnet-format.sh
+++ b/src/run-dotnet-format.sh
@@ -1,6 +1,6 @@
#!/bin/sh
set -e
-dotnet tool update -g dotnet-format
-dotnet format --check --verbosity diagnostic
+dotnet tool update dotnet-format
+dotnet format --verbosity diagnostic
diff --git a/src/run-security-code-scan.sh b/src/run-security-code-scan.sh
new file mode 100755
index 0000000..4e3b2f0
--- /dev/null
+++ b/src/run-security-code-scan.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+set -e
+
+dotnet tool update security-scan
+dotnet security-scan ./ByteDecoder.Common.sln
\ No newline at end of file
diff --git a/src/win-run-dotnet-format.bat b/src/win-run-dotnet-format.bat
index d2d3028..4cfd13d 100644
--- a/src/win-run-dotnet-format.bat
+++ b/src/win-run-dotnet-format.bat
@@ -4,5 +4,5 @@ cls
echo Legion awaits
-dotnet tool update -g dotnet-format
-dotnet format --check --verbosity diagnostic
\ No newline at end of file
+dotnet tool update dotnet-format
+dotnet format --verbosity diagnostic
\ No newline at end of file
diff --git a/src/win-security-code-scan.bat b/src/win-security-code-scan.bat
new file mode 100644
index 0000000..16083e3
--- /dev/null
+++ b/src/win-security-code-scan.bat
@@ -0,0 +1,2 @@
+dotnet tool update security-scan
+dotnet security-scan .\ByteDecoder.Common.sln
\ No newline at end of file