Skip to content

Commit

Permalink
Working
Browse files Browse the repository at this point in the history
  • Loading branch information
Aldaviva committed Nov 7, 2023
0 parents commit 5c1f525
Show file tree
Hide file tree
Showing 22 changed files with 857 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "nuget"
directory: "/Bom.Squad"
schedule:
interval: "weekly"
57 changes: 57 additions & 0 deletions .github/workflows/dotnetpackage.yml
@@ -0,0 +1,57 @@
name: .NET

on:
push:
branches: [ master ]

workflow_dispatch:

jobs:
build:
env:
ProjectName: Bom.Squad

runs-on: windows-latest

steps:
- name: Clone
uses: actions/checkout@v3

- name: Initialize test reporting
uses: testspace-com/setup-testspace@v1
with:
domain: ${{github.repository_owner}}

- name: Restore
run: dotnet restore --verbosity normal

- name: Build
run: dotnet build --no-restore --configuration Release --verbosity normal

- name: Test
run: |
dotnet test --no-build --verbosity normal --configuration Release --collect:"XPlat Code Coverage" --settings Test/Test.runsettings --logger "trx;LogFileName=TestResults.xml"
Out-File -InputObject "TEST_EXIT_CODE=$LASTEXITCODE" -FilePath $env:GITHUB_ENV -Append -Encoding UTF8
Copy-Item Test/TestResults/*/coverage.info Test/TestResults -ErrorAction Continue
exit 0
- name: Upload test report
run: testspace Test/TestResults/TestResults.xml

- name: Upload coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: Test/TestResults/coverage.info

- name: Stop if tests failed
run: exit $env:TEST_EXIT_CODE

- name: Pack
run: dotnet pack ${{ env.ProjectName }} --no-build --configuration Release --verbosity normal

- name: Upload package
uses: actions/upload-artifact@v3
with:
name: ${{ env.ProjectName }}.nupkg
path: ${{ env.ProjectName }}/bin/Release/*.*nupkg
32 changes: 32 additions & 0 deletions .gitignore
@@ -0,0 +1,32 @@

#Ignore thumbnails created by Windows
Thumbs.db
#Ignore files built by Visual Studio
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
[Tt]est[Rr]esult*
.vs/
#Nuget packages folder
packages/
31 changes: 31 additions & 0 deletions Bom.Squad.sln
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34221.43
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{FDC49FE7-C032-4C40-87FE-DA52078465FE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bom.Squad", "Bom.Squad\Bom.Squad.csproj", "{06F9E300-025A-479D-AE1D-53CBB811E9FA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FDC49FE7-C032-4C40-87FE-DA52078465FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FDC49FE7-C032-4C40-87FE-DA52078465FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDC49FE7-C032-4C40-87FE-DA52078465FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDC49FE7-C032-4C40-87FE-DA52078465FE}.Release|Any CPU.Build.0 = Release|Any CPU
{06F9E300-025A-479D-AE1D-53CBB811E9FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06F9E300-025A-479D-AE1D-53CBB811E9FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06F9E300-025A-479D-AE1D-53CBB811E9FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06F9E300-025A-479D-AE1D-53CBB811E9FA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {89387E35-7B5B-4612-AFED-22DFCF6EA820}
EndGlobalSection
EndGlobal
22 changes: 22 additions & 0 deletions Bom.Squad.sln.DotSettings
@@ -0,0 +1,22 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Constants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=EnumMember/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Event/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Interfaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=LocalConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=LocalFunctions/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Locals/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Method/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Other/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Parameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Property/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PublicFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypeParameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=_002A_003B_002A_003BBom_002ESquad_002EInternal_002EMethodRedirect_002E_002A_003B_002A/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
43 changes: 43 additions & 0 deletions Bom.Squad/Bom.Squad.csproj
@@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net452;netstandard2.0</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>

<Version>0.0.0</Version>
<Authors>Ben Hutchison</Authors>
<Copyright>© 2023 $(Authors)</Copyright>
<Company>$(Authors)</Company>
<NoWarn>CS8524</NoWarn>

<PackageProjectUrl>https://github.com/Aldaviva/Bom.Squad</PackageProjectUrl>
<RepositoryUrl>https://github.com/Aldaviva/Bom.Squad.git</RepositoryUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>utf utf8 unicode bom byte-order-marker</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSource>true</IncludeSource>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="icon.png" Pack="true" PackagePath="\" />
<None Include="..\Readme.md" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true' or '$(Configuration)' == 'Release'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

</Project>
2 changes: 2 additions & 0 deletions Bom.Squad/Bom.Squad.csproj.DotSettings
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=methodredirect/@EntryIndexedValue">False</s:Boolean></wpf:ResourceDictionary>
43 changes: 43 additions & 0 deletions Bom.Squad/BomSquad.cs
@@ -0,0 +1,43 @@
using Bom.Squad.Internal.MethodRedirect;
using System.Reflection;
using System.Text;

namespace Bom.Squad;

/// <summary>
/// <para>Allows you to modify the base class library <see cref="Encoding.UTF8"/> to not output byte order markers when encoding, although it will parse them correctly.</para>
/// <para>Other encodings, such as <see cref="Encoding.Unicode"/> and <c>new UTF8Encoding(true, true)</c>, will not be affected.</para>
///
/// <para>Usage:</para>
/// <para><c>BomSquad.DefuseUtf8Bom();</c></para>
/// </summary>
public static class BomSquad {

/// <summary>
/// A UTF-8 <see cref="Encoding"/> instance that does not output byte order markers when encoding, although it will parse them correctly.
/// It throws exceptions when invalid bytes are detected.
/// </summary>
public static readonly Encoding Utf8NoBom = new UTF8Encoding(false, true);

private static bool _armed = true;

/// <summary>
/// <para>Modify the base class library <see cref="Encoding.UTF8"/> to not output byte order markers when encoding, although it will parse them correctly.</para>
/// <para>After calling this method, subsequent calls to <see cref="Encoding.UTF8"/> will not write BOMs.</para>
/// <para>Other encodings, such as <see cref="Encoding.Unicode"/> and <c>new UTF8Encoding(true, true)</c>, will not be affected.</para>
/// </summary>
// ExceptionAdjustment: M:System.Type.GetProperty(System.String,System.Reflection.BindingFlags) -T:System.Reflection.AmbiguousMatchException
// ExceptionAdjustment: M:System.Type.GetMethod(System.String,System.Reflection.BindingFlags) -T:System.Reflection.AmbiguousMatchException
public static void DefuseUtf8Bom() {
if (_armed) {
MethodInfo oldMethod = typeof(Encoding).GetProperty("UTF8", BindingFlags.Static | BindingFlags.Public | BindingFlags.GetProperty)!.GetMethod;
MethodInfo newMethod = typeof(BomSquad).GetMethod(nameof(Utf8), BindingFlags.Static | BindingFlags.NonPublic)!;

oldMethod.RedirectTo(newMethod, true);
_armed = false;
}
}

private static Encoding Utf8() => Utf8NoBom;

}
3 changes: 3 additions & 0 deletions Bom.Squad/GlobalUsings.cs
@@ -0,0 +1,3 @@
// Global using directives

global using System;
41 changes: 41 additions & 0 deletions Bom.Squad/Internal/MethodRedirect/.editorconfig
@@ -0,0 +1,41 @@
[*]

# Exception Analyzers: Exception adjustments syntax error
# default = error
; dotnet_diagnostic.Ex0001.severity = none

# Exception Analyzers: Exception adjustments syntax error: Symbol does not exist or identifier is invalid
# default = warning
; dotnet_diagnostic.Ex0002.severity = none

# Exception Analyzers: Member may throw undocumented exception
# default = warning
dotnet_diagnostic.Ex0100.severity = none

# Exception Analyzers: Member accessor may throw undocumented exception
# default = warning
dotnet_diagnostic.Ex0101.severity = none

# Exception Analyzers: Implicit constructor may throw undocumented exception
# default = warning
dotnet_diagnostic.Ex0103.severity = none

# Exception Analyzers: Member initializer may throw undocumented exception
# default = warning
dotnet_diagnostic.Ex0104.severity = none

# Exception Analyzers: Delegate created from member may throw undocumented exception
# default = silent
; dotnet_diagnostic.Ex0120.severity = none

# Exception Analyzers: Delegate created from anonymous function may throw undocumented exception
# default = silent
; dotnet_diagnostic.Ex0121.severity = none

# Exception Analyzers: Member is documented as throwing exception not documented on member in base or interface type
# default = warning
dotnet_diagnostic.Ex0200.severity = none

# Exception Analyzers: Member accessor is documented as throwing exception not documented on member in base or interface type
# default = warning
dotnet_diagnostic.Ex0201.severity = none

0 comments on commit 5c1f525

Please sign in to comment.