Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ env:
jobs:
pack:

runs-on: [windows-2019]
runs-on: [windows-latest]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install .NET Framework 4.6.1 Developer Pack
run: choco install netfx-4.6.1-devpack -y

- name: Setup .NET 2.0
uses: actions/setup-dotnet@v1
with:
Expand All @@ -44,8 +47,24 @@ jobs:
- name: Restore NuGet packages.sln
run: nuget restore ./src/${{ env.FILE_NAME}}.sln

- name: Build Solution
run: msbuild ./src/${{ env.FILE_NAME}}.sln /p:Configuration=Release

- name: Prepare .nuspec
run: |
$nuspecPath = "src/${{ env.FILE_NAME }}.nuspec.in"
$nuspec = Get-Content $nuspecPath
$nuspec = $nuspec -replace '\$\{\{ env.FILE_NAME \}\}', '${{ env.FILE_NAME }}'
$nuspec = $nuspec -replace '\$\{\{ env.TITLE \}\}', '${{ env.TITLE }}'
$nuspec = $nuspec -replace '\$\{\{ env.DESCRIPTION \}\}', '${{ env.DESCRIPTION }}'
$nuspec = $nuspec -replace '\$\{\{ env.TAGS \}\}', '${{ env.TAGS }}'
$nuspec = $nuspec -replace '\$\{\{ env.GITHUB_URL \}\}', '${{ env.GITHUB_URL }}'
$nuspec = $nuspec -replace '\$\{\{ env.REPOSITORY_URL \}\}', '${{ env.REPOSITORY_URL }}'
Set-Content ThunderDesign.Net-PCL.nuspec $nuspec
shell: pwsh

- name: Create NuGet Package
run: msbuild ./src/${{ env.FILE_NAME}}.sln -t:pack /p:VersionPrefix=${{ github.event.release.tag_name }} /p:Configuration=Release /p:Title="${{ env.TITLE }}" /p:Description="${{ env.DESCRIPTION }}" /p:PackageTags="${{ env.TAGS }}" /p:Authors=ThunderDesign /p:PackageProjectUrl=${{ env.GITHUB_URL }} /p:PackageLicenseExpression=MIT /p:RepositoryType=git /p:RepositoryUrl=${{ env.REPOSITORY_URL }} /p:PackageReleaseNotes="See ${{ env.REPOSITORY_URL }}/releases/tag/${{ github.event.release.tag_name }}" /p:PackageReadmeFile="README.md" /p:PackageOutputPath=${{ env.PACKAGE_OUTPUT_DIRECTORY}}
run: nuget pack ThunderDesign.Net-PCL.nuspec -Version ${{ github.event.release.tag_name }} -OutputDirectory ${{ env.PACKAGE_OUTPUT_DIRECTORY }}

- name: Archive NuGet Package
uses: actions/upload-artifact@v2.3.1
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ env:
jobs:
build:

runs-on: [windows-2019]
runs-on: [windows-latest]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install .NET Framework 4.6.1 Developer Pack
run: choco install netfx-4.6.1-devpack -y

- name: Setup .NET 2.0
uses: actions/setup-dotnet@v1
with:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ A set of core methods and classes to ease every days .NET development tasks.
- StringExtentions
- TypeExtentions

- Helpers
- EqualityHelper

----

## Installation
Expand Down
109 changes: 109 additions & 0 deletions src/ThunderDesign.Net-PCL.ToolBox/Helpers/EqualityHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

namespace ThunderDesign.Net_PCL.ToolBox.Helpers
{
public static class EqualityHelper
{
public static bool Equality<T>(ref T backingStore, T value)
{
if (typeof(T) == typeof(string))
{
return StringEquality(ref backingStore, value);
}
else if (typeof(IStructuralEquatable).IsAssignableFrom(typeof(T)))
{
return StructureEquality(ref backingStore, value);
}
else if (typeof(T).IsValueType)
{
return ValueEquality(ref backingStore, value);
}
else
{
return ReferenceEquality(ref backingStore, value);
}
}

/// <summary>
/// Checks for equality between two string values.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="backingStore"></param>
/// <param name="value"></param>
/// <returns cref="bool" indicating whether the two values are equal.></returns>
/// <exception cref="InvalidOperationException"></exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool StringEquality<T>(ref T backingStore, T value)
{
if (typeof(T) != typeof(string))
{
throw new InvalidOperationException($"Type: {typeof(T)} cannot be used with string types.");
}

return string.Equals(backingStore as string, value as string, StringComparison.Ordinal);
}

/// <summary>
/// Checks for equality between two structural values.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="backingStore"></param>
/// <param name="value"></param>
/// <returns cref="bool" indicating whether the two values are equal.></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool StructureEquality<T>(ref T backingStore, T value)
{
if (!typeof(IStructuralEquatable).IsAssignableFrom(typeof(T)))
{
throw new InvalidOperationException($"Type: {typeof(T)} cannot be used with structural types.");
}
else if (backingStore == null && value == null)
{
return true;
}
else if (backingStore == null || value == null)
{
return false;
}

var structuralEquatable = backingStore as IStructuralEquatable;
return structuralEquatable.Equals(value, StructuralComparisons.StructuralEqualityComparer);
}

/// <summary>
/// Checks for equality between two value types.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="backingStore"></param>
/// <param name="value"></param>
/// <returns cref="bool" indicating whether the two values are equal.></returns>
/// <exception cref="InvalidOperationException"></exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool ValueEquality<T>(ref T backingStore, T value)
{
if (!typeof(T).IsValueType)
{
throw new InvalidOperationException($"Type: {typeof(T)} cannot be used with value types.");
}

return EqualityComparer<T>.Default.Equals(backingStore, value);
}

/// <summary>
/// Checks for equality between two reference types.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="backingStore"></param>
/// <param name="value"></param>
/// <returns cref="bool" indicating whether the two values are equal.></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool ReferenceEquality<T>(ref T backingStore, T value)
{
return ReferenceEquals(backingStore, value);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.0;netstandard2.0;net461</TargetFrameworks>
Expand All @@ -8,6 +8,10 @@
<PropertyGroup Condition=" '$(TargetFramework)' == 'net461' ">
<DefineConstants>NETSTANDARD1_4</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' ">
<Compile Remove="**\EqualityHelper.cs" />
<None Include="**\EqualityHelper.cs" Pack="false" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\README.md">
<Pack>True</Pack>
Expand Down
29 changes: 29 additions & 0 deletions src/ThunderDesign.Net-PCL.Toolbox.nuspec.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>${{ env.FILE_NAME }}</id>
<version>$version$</version>
<title>${{ env.TITLE }}</title>
<authors>ThunderDesign</authors>
<owners>ThunderDesign</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<projectUrl>${{ env.GITHUB_URL }}</projectUrl>
<description>${{ env.DESCRIPTION }}</description>
<releaseNotes>See ${{ env.REPOSITORY_URL }}/releases/tag/$version$</releaseNotes>
<tags>${{ env.TAGS }}</tags>
<repository type="git" url="${{ env.REPOSITORY_URL }}" />
<readme>README.md</readme>
<dependencies>
<group targetFramework="netstandard1.0" />
<group targetFramework="netstandard2.0" />
<group targetFramework="net461" />
</dependencies>
</metadata>
<files>
<file src="src/ThunderDesign.Net-PCL.ToolBox/bin/Release/netstandard1.0/ThunderDesign.Net-PCL.ToolBox.dll" target="lib/netstandard1.0/" />
<file src="src/ThunderDesign.Net-PCL.ToolBox/bin/Release/netstandard2.0/ThunderDesign.Net-PCL.ToolBox.dll" target="lib/netstandard2.0/" />
<file src="src/ThunderDesign.Net-PCL.ToolBox/bin/Release/net461/ThunderDesign.Net-PCL.ToolBox.dll" target="lib/net461/" />
<file src="README.md" target="" />
</files>
</package>
Loading