Skip to content

Commit 069e103

Browse files
committedJan 2, 2022
Feature completed
1 parent 19cc59d commit 069e103

15 files changed

+159
-91
lines changed
 

‎src/.config/dotnet-tools.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"security-scan": {
6+
"version": "5.6.0",
7+
"commands": ["security-scan"]
8+
},
9+
"dotnet-format": {
10+
"version": "5.1.250801",
11+
"commands": ["dotnet-format"]
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,42 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp3.1</TargetFramework>
3+
<TargetFramework>net6.0</TargetFramework>
4+
<Nullable>enable</Nullable>
45
<IsPackable>false</IsPackable>
56
</PropertyGroup>
7+
<PropertyGroup>
8+
<CodeAnalysisRuleSet>$(SolutionDir)\_stylecop\TestProjStyleCopRules.ruleset</CodeAnalysisRuleSet>
9+
</PropertyGroup>
10+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
11+
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
12+
<TreatSpecificWarningsAsErrors/>
13+
<NoWarn>1701;1702;1705</NoWarn>
14+
</PropertyGroup>
615
<ItemGroup>
7-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
8-
<PackageReference Include="xunit" Version="2.4.1" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0"/>
17+
<PackageReference Include="xunit" Version="2.4.1"/>
918
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
1019
<PrivateAssets>all</PrivateAssets>
1120
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1221
</PackageReference>
13-
<PackageReference Include="coverlet.collector" Version="1.3.0">
14-
<PrivateAssets>all</PrivateAssets>
15-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16-
</PackageReference>
17-
<PackageReference Include="coverlet.msbuild" Version="2.9.0" />
18-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1">
22+
<PackageReference Include="coverlet.collector" Version="3.1.0">
1923
<PrivateAssets>all</PrivateAssets>
2024
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2125
</PackageReference>
26+
<PackageReference Include="coverlet.msbuild" Version="3.1.0"/>
27+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0"/>
2228
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
2329
<PrivateAssets>all</PrivateAssets>
2430
</PackageReference>
31+
<PackageReference Include="xunit.analyzers" Version="0.10.0"/>
2532
</ItemGroup>
2633
<ItemGroup>
27-
<ProjectReference Include="..\ByteDecoder.Common\ByteDecoder.Common.csproj" />
34+
<ProjectReference Include="..\ByteDecoder.Common\ByteDecoder.Common.csproj"/>
2835
</ItemGroup>
29-
3036
<ItemGroup>
31-
<AdditionalFiles Include="$(SolutionDir)\_stylecop\stylecop.json" Link="stylecop.json" />
37+
<AdditionalFiles Include="$(SolutionDir)\_stylecop\stylecop.json" Link="stylecop.json"/>
3238
</ItemGroup>
33-
34-
<PropertyGroup>
35-
<CodeAnalysisRuleSet>$(SolutionDir)\_stylecop\TestProjStyleCopRules.ruleset</CodeAnalysisRuleSet>
36-
</PropertyGroup>
37-
38-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
39-
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
40-
<TreatSpecificWarningsAsErrors />
41-
<NoWarn>1701;1702;1705</NoWarn>
39+
<PropertyGroup>
40+
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
4241
</PropertyGroup>
43-
4442
</Project>

‎src/ByteDecoder.Common.Tests/GuardTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void ThrowIfArgumentIsNull_ThrowsNullArgumentException_WhenSourceIsNull()
2121
// Act
2222
var exception = Record.Exception(() =>
2323
{
24-
Guard.Break.IfArgumentIsNull((IEnumerable<string>)null, "collection");
24+
Guard.Break.IfArgumentIsNull<IEnumerable<string>?>(null, "collection");
2525
});
2626

2727
// Assert
@@ -49,7 +49,7 @@ public void ThrowIfArgumentIsNullWithMessage_ThrowsNullArgumentException_WhenSou
4949
// Act
5050
var exception = Record.Exception(() =>
5151
{
52-
Guard.Break.IfArgumentIsNull((IEnumerable<string>)null, "collection", "An error occurred");
52+
Guard.Break.IfArgumentIsNull((IEnumerable<string>?)null, "collection", "An error occurred");
5353
});
5454

5555
// Assert

‎src/ByteDecoder.Common.sln

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26124.0
5-
MinimumVisualStudioVersion = 15.0.26124.0
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30114.105
5+
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ByteDecoder.Common", "ByteDecoder.Common\ByteDecoder.Common.csproj", "{8E47AA9F-A9AE-4104-B3EF-DDEC366C9D94}"
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ByteDecoder.Common.Tests", "ByteDecoder.Common.Tests\ByteDecoder.Common.Tests.csproj", "{127AD73D-0572-4D6E-9EF2-23909C5A84E3}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma warning disable SA1516
2+
3+
[assembly: CLSCompliant(true)]
4+
namespace ByteDecoder.Common;
5+
6+
#pragma warning restore SA1516
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netstandard2.0</TargetFramework>
3+
<TargetFramework>net6.0</TargetFramework>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
46
</PropertyGroup>
7+
58
<PropertyGroup>
6-
<TargetFramework>netstandard2.0</TargetFramework>
9+
<TargetFramework>net6.0</TargetFramework>
710
<RootNamespace>ByteDecoder.Common</RootNamespace>
811
<Authors>ByteDecoder</Authors>
9-
<Company />
12+
<Company/>
1013
<PackageId>ByteDecoder.Common</PackageId>
1114
<Title>ByteDecoder.Common</Title>
1215
<Description>Common utility classes</Description>
@@ -24,39 +27,49 @@
2427
<Summary>Common utility classes</Summary>
2528
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
2629
</PropertyGroup>
30+
2731
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
2832
<DefineConstants>TRACE;JETBRAINS_ANNOTATIONS</DefineConstants>
29-
3033
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
31-
<TreatSpecificWarningsAsErrors />
34+
<TreatSpecificWarningsAsErrors/>
3235
<NoWarn>1701;1702;1705</NoWarn>
3336
<DocumentationFile>bin\Debug\netstandard2.0\ByteDecoder.Common.xml</DocumentationFile>
3437
</PropertyGroup>
38+
39+
<PropertyGroup>
40+
<CodeAnalysisRuleSet>$(SolutionDir)\_stylecop\LibraryStyleCopRules.ruleset</CodeAnalysisRuleSet>
41+
</PropertyGroup>
42+
3543
<ItemGroup>
3644
<None Include="..\..\LICENSE">
3745
<Pack>True</Pack>
38-
<PackagePath />
46+
<PackagePath/>
3947
</None>
4048
</ItemGroup>
49+
4150
<ItemGroup>
42-
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
43-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1">
51+
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0"/>
52+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
4453
<PrivateAssets>all</PrivateAssets>
4554
</PackageReference>
46-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
55+
<PackageReference Include="NuGetDefense" Version="2.1.2.1">
4756
<PrivateAssets>all</PrivateAssets>
4857
</PackageReference>
58+
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.0">
59+
<PrivateAssets>all</PrivateAssets>
60+
</PackageReference>
61+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0"/>
4962
</ItemGroup>
63+
64+
<PropertyGroup>
65+
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
66+
</PropertyGroup>
67+
5068
<ItemGroup>
51-
<None Include="icon.png" Pack="true" Visible="false" PackagePath="" />
69+
<None Include="icon.png" Pack="true" Visible="false" PackagePath=""/>
5270
</ItemGroup>
5371

5472
<ItemGroup>
55-
<AdditionalFiles Include="$(SolutionDir)\_stylecop\stylecop.json" Link="stylecop.json" />
73+
<AdditionalFiles Include="$(SolutionDir)\_stylecop\stylecop.json" Link="stylecop.json"/>
5674
</ItemGroup>
57-
58-
<PropertyGroup>
59-
<CodeAnalysisRuleSet>$(SolutionDir)\_stylecop\LibraryStyleCopRules.ruleset</CodeAnalysisRuleSet>
60-
</PropertyGroup>
61-
6275
</Project>
+26-29
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
using System;
1+
namespace ByteDecoder.Common;
22

3-
namespace ByteDecoder.Common
3+
/// <summary>
4+
/// Enum type extensions.
5+
/// </summary>
6+
public static class EnumExtensions
47
{
58
/// <summary>
6-
/// Enum type extensions.
9+
/// Converts a string value to an Enum value.
710
/// </summary>
8-
public static class EnumExtensions
11+
/// <typeparam name="T">Enum type.</typeparam>
12+
/// <param name="value">Value to convert.</param>
13+
/// <returns>Enum value.</returns>
14+
public static T ToEnum<T>(this string value) where T : struct
915
{
10-
/// <summary>
11-
/// Converts a string value to an Enum value.
12-
/// </summary>
13-
/// <typeparam name="T">Enum type.</typeparam>
14-
/// <param name="value">Value to convert.</param>
15-
/// <returns>Enum value.</returns>
16-
public static T ToEnum<T>(this string value) where T : struct, IConvertible
17-
{
18-
return (T)Enum.Parse(typeof(T), value, true);
19-
}
16+
return (T)Enum.Parse(typeof(T), value, true);
17+
}
2018

21-
/// <summary>
22-
/// Converts a string value to an Enum value, if fails returns the default value
23-
/// specified.
24-
/// </summary>
25-
/// <typeparam name="T">Enum type.</typeparam>
26-
/// <param name="value">Value to convert.</param>
27-
/// <param name="defaultValue">Default enum value.</param>
28-
/// <returns>Enum value.</returns>
29-
public static T ToEnum<T>(this string value, T defaultValue) where T : struct, IConvertible
30-
{
31-
if (string.IsNullOrWhiteSpace(value))
32-
return defaultValue;
19+
/// <summary>
20+
/// Converts a string value to an Enum value, if fails returns the default value
21+
/// specified.
22+
/// </summary>
23+
/// <typeparam name="T">Enum type.</typeparam>
24+
/// <param name="value">Value to convert.</param>
25+
/// <param name="defaultValue">Default enum value.</param>
26+
/// <returns>Enum value.</returns>
27+
public static T ToEnum<T>(this string value, T defaultValue) where T : struct
28+
{
29+
if (string.IsNullOrWhiteSpace(value))
30+
return defaultValue;
3331

34-
T result;
35-
return Enum.TryParse<T>(value, true, out result) ? result : defaultValue;
36-
}
32+
T result;
33+
return Enum.TryParse<T>(value, true, out result) ? result : defaultValue;
3734
}
3835
}

‎src/ByteDecoder.Common/GuardClauses/Guard.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using JetBrains.Annotations;
1+
using JetBrains.Annotations;
32

43
namespace ByteDecoder.Common.GuardClauses
54
{
@@ -22,7 +21,7 @@ private Guard() { }
2221
/// <typeparam name="T">Generic type for the guard.</typeparam>
2322
/// <param name="source">Instance source.</param>
2423
/// <param name="paramName">Param name.</param>
25-
public void IfArgumentIsNull<T>([NoEnumeration][ValidatedNotNull] T source, string paramName) where T : class
24+
public void IfArgumentIsNull<T>([NoEnumeration][ValidatedNotNull] T source, string paramName)
2625
{
2726
if (source == null)
2827
throw new ArgumentNullException(paramName);
@@ -35,7 +34,10 @@ public void IfArgumentIsNull<T>([NoEnumeration][ValidatedNotNull] T source, stri
3534
/// <param name="source">Instance source.</param>
3635
/// <param name="paramName">Param name.</param>
3736
/// <param name="message">Message if guard clause breaks.</param>
38-
public void IfArgumentIsNull<T>([NoEnumeration][ValidatedNotNull] T source, string paramName, string message) where T : class
37+
public void IfArgumentIsNull<T>(
38+
[NoEnumeration][ValidatedNotNull] T source,
39+
string paramName,
40+
string message)
3941
{
4042
if (source == null)
4143
throw new ArgumentNullException(paramName, message);
@@ -46,7 +48,7 @@ public void IfArgumentIsNull<T>([NoEnumeration][ValidatedNotNull] T source, stri
4648
/// </summary>
4749
/// <param name="source">Instance source.</param>
4850
/// <param name="paramName">Param name.</param>
49-
public void IfArgumentIsNullOrEmpty(string source, string paramName)
51+
public void IfArgumentIsNullOrEmpty(string? source, string paramName)
5052
{
5153
if (string.IsNullOrEmpty(source))
5254
throw new ArgumentNullException(paramName);
@@ -58,7 +60,7 @@ public void IfArgumentIsNullOrEmpty(string source, string paramName)
5860
/// <param name="source">Instance source.</param>
5961
/// <param name="paramName">Param name.</param>
6062
/// <param name="message">Message if guard clause breaks.</param>
61-
public void IfArgumentIsNullOrEmpty(string source, string paramName, string message)
63+
public void IfArgumentIsNullOrEmpty(string? source, string paramName, string message)
6264
{
6365
if (string.IsNullOrEmpty(source))
6466
throw new ArgumentNullException(paramName, message);

‎src/ByteDecoder.Common/GuardClauses/IGuardClause.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using JetBrains.Annotations;
1+
using JetBrains.Annotations;
32

43
namespace ByteDecoder.Common.GuardClauses
54
{
@@ -14,7 +13,7 @@ public interface IGuardClause
1413
/// <typeparam name="T">Generic type for the guard.</typeparam>
1514
/// <param name="source">Instance source.</param>
1615
/// <param name="paramName">Param name.</param>
17-
void IfArgumentIsNull<T>([NoEnumeration][ValidatedNotNull] T source, string paramName) where T : class;
16+
void IfArgumentIsNull<T>([NoEnumeration][ValidatedNotNull] T source, string paramName);
1817

1918
/// <summary>
2019
/// Guard and check a value if is not null.
@@ -23,22 +22,25 @@ public interface IGuardClause
2322
/// <param name="source">Instance source.</param>
2423
/// <param name="paramName">Param name.</param>
2524
/// <param name="message">Message if guard clause breaks.</param>
26-
void IfArgumentIsNull<T>([NoEnumeration][ValidatedNotNull] T source, string paramName, string message) where T : class;
25+
void IfArgumentIsNull<T>(
26+
[NoEnumeration][ValidatedNotNull] T source,
27+
string paramName,
28+
string message);
2729

2830
/// <summary>
2931
/// Guard and check a value if is not null or neither empty.
3032
/// </summary>
3133
/// <param name="source">Instance source.</param>
3234
/// <param name="paramName">Param name.</param>
33-
void IfArgumentIsNullOrEmpty(string source, string paramName);
35+
void IfArgumentIsNullOrEmpty(string? source, string paramName);
3436

3537
/// <summary>
3638
/// Guard and check a value if is not null or neither empty.
3739
/// </summary>
3840
/// <param name="source">Instance source.</param>
3941
/// <param name="paramName">Param name.</param>
4042
/// <param name="message">Message if guard clause breaks.</param>
41-
void IfArgumentIsNullOrEmpty(string source, string paramName, string message);
43+
void IfArgumentIsNullOrEmpty(string? source, string paramName, string message);
4244

4345
/// <summary>
4446
/// Guard and check a value if is in a range.
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"WarnOnly": false,
3+
"VulnerabilityReports": {
4+
"OutputTextReport": true
5+
},
6+
"CheckTransitiveDependencies": true,
7+
"CheckReferencedProjects": false,
8+
"ErrorSettings": {
9+
"ErrorSeverityThreshold": "any",
10+
"Cvss3Threshold": -1,
11+
"IgnoredPackages": [
12+
{
13+
"Id": "NugetDefense"
14+
}
15+
],
16+
"IgnoredCvEs": [],
17+
"AllowedPackages": [],
18+
"BlockedPackages": []
19+
},
20+
"OssIndex": {
21+
"ApiToken": "",
22+
"Username": "",
23+
"Enabled": true,
24+
"BreakIfCannotRun": true
25+
},
26+
"NVD": {
27+
"SelfUpdate": false,
28+
"TimeoutInSeconds": 15,
29+
"Enabled": true,
30+
"BreakIfCannotRun": true
31+
},
32+
"SensitivePackages": []
33+
}

‎src/_stylecop/TestProjStyleCopRules.ruleset

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<IncludeAll Action="Warning" />
44
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
55
<Rule Id="CA1707" Action="None" />
6+
<Rule Id="CA1014" Action="None" />
67
</Rules>
78
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
89
<Rule Id="SA0001" Action="None" />

‎src/global.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "3.1.405"
3+
"version": "6.0.101"
44
}
55
}

‎src/run-dotnet-format.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
set -e
33

4-
dotnet tool update -g dotnet-format
5-
dotnet format --check --verbosity diagnostic
4+
dotnet tool update dotnet-format
5+
dotnet format --verbosity diagnostic
66

‎src/win-run-dotnet-format.bat

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ cls
44

55
echo Legion awaits
66

7-
dotnet tool update -g dotnet-format
8-
dotnet format --check --verbosity diagnostic
7+
dotnet tool update dotnet-format
8+
dotnet format --verbosity diagnostic

‎src/win-security-code-scan.bat

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dotnet tool update security-scan
2+
dotnet security-scan .\ByteDecoder.Common.sln

0 commit comments

Comments
 (0)
Please sign in to comment.