Skip to content

Commit 36877f7

Browse files
Merge pull request #4 from onix-labs/feature/3.1.0
feature/3.1.0
2 parents dfe07e6 + 8db27ae commit 36877f7

21 files changed

+272
-51
lines changed

OnixLabs.Core/Enumeration.Equatable.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ public override bool Equals(object? obj)
7070
/// <returns>A hash code for this instance.</returns>
7171
public override int GetHashCode()
7272
{
73-
return new HashCode()
74-
.AddItem(GetType())
75-
.AddItem(Name)
76-
.AddItem(Value)
77-
.ToHashCode();
73+
return HashCode.Combine(GetType(), Name, Value);
7874
}
7975
}
8076
}

OnixLabs.Core/Linq/IEnumerableExtensions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ public static bool AnyEqualBy<TElement, TProperty>(
8484
return elements.Any(element => Equals(first, selector(element)));
8585
}
8686

87+
/// <summary>
88+
/// Computes the content hash code of the elements of this <see cref="IEnumerable{T}"/>.
89+
/// </summary>
90+
/// <param name="enumerable">The <see cref="IEnumerable{T}"/> from which to compute a content hash code.</param>
91+
/// <typeparam name="T">The underlying type of the <see cref="IEnumerable{T}"/>.</typeparam>
92+
/// <returns>Returns the computed content hash code of this <see cref="IEnumerable{T}"/>.</returns>
93+
public static int ComputeContentHashCode<T>(this IEnumerable<T> enumerable)
94+
{
95+
return new HashCode().AddItems(enumerable).ToHashCode();
96+
}
97+
8798
/// <summary>
8899
/// Performs the specified <see cref="Action{T}"/> for each element of this <see cref="IEnumerable{T}"/>.
89100
/// </summary>

OnixLabs.Core/OnixLabs.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<NeutralLanguage>en</NeutralLanguage>
1313
<Copyright>Copyright © ONIXLabs 2020-2021</Copyright>
1414
<RepositoryUrl>https://github.com/onix-labs/onixlabs-dotnet</RepositoryUrl>
15-
<PackageVersion>3.0.0</PackageVersion>
15+
<PackageVersion>3.1.0</PackageVersion>
1616
</PropertyGroup>
1717

1818
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

OnixLabs.Core/Text/Base16.Empty.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2020-2021 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
17+
namespace OnixLabs.Core.Text
18+
{
19+
public readonly partial struct Base16
20+
{
21+
/// <summary>
22+
/// Gets an empty Base-16 value.
23+
/// </summary>
24+
public static readonly Base16 Empty;
25+
26+
/// <summary>
27+
/// Initializes static members of the <see cref="Base16"/> class.
28+
/// </summary>
29+
static Base16()
30+
{
31+
Empty = FromByteArray(Array.Empty<byte>());
32+
}
33+
}
34+
}

OnixLabs.Core/Text/Base16.Equatable.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System;
1616
using System.Linq;
17+
using OnixLabs.Core.Linq;
1718

1819
namespace OnixLabs.Core.Text
1920
{
@@ -67,9 +68,7 @@ public override bool Equals(object? obj)
6768
/// <returns>A hash code for this instance.</returns>
6869
public override int GetHashCode()
6970
{
70-
return new HashCode()
71-
.AddItems(Value)
72-
.ToHashCode();
71+
return HashCode.Combine(Value.ComputeContentHashCode());
7372
}
7473
}
7574
}

OnixLabs.Core/Text/Base32.Empty.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2020-2021 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
17+
namespace OnixLabs.Core.Text
18+
{
19+
public readonly partial struct Base32
20+
{
21+
/// <summary>
22+
/// Gets an empty Base-32 value.
23+
/// </summary>
24+
public static readonly Base32 Empty;
25+
26+
/// <summary>
27+
/// Initializes static members of the <see cref="Base32"/> class.
28+
/// </summary>
29+
static Base32()
30+
{
31+
Empty = FromByteArray(Array.Empty<byte>());
32+
}
33+
}
34+
}

OnixLabs.Core/Text/Base32.Equatable.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System;
1616
using System.Linq;
17+
using OnixLabs.Core.Linq;
1718

1819
namespace OnixLabs.Core.Text
1920
{
@@ -69,9 +70,7 @@ public override bool Equals(object? obj)
6970
/// <returns>A hash code for this instance.</returns>
7071
public override int GetHashCode()
7172
{
72-
return new HashCode()
73-
.AddItems(Value)
74-
.ToHashCode();
73+
return HashCode.Combine(Value.ComputeContentHashCode());
7574
}
7675
}
7776
}

OnixLabs.Core/Text/Base58.Empty.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2020-2021 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
17+
namespace OnixLabs.Core.Text
18+
{
19+
public readonly partial struct Base58
20+
{
21+
/// <summary>
22+
/// Gets an empty Base-58 value.
23+
/// </summary>
24+
public static readonly Base58 Empty;
25+
26+
/// <summary>
27+
/// Initializes static members of the <see cref="Base58"/> class.
28+
/// </summary>
29+
static Base58()
30+
{
31+
Empty = FromByteArray(Array.Empty<byte>());
32+
}
33+
}
34+
}

OnixLabs.Core/Text/Base58.Equatable.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System;
1616
using System.Linq;
17+
using OnixLabs.Core.Linq;
1718

1819
namespace OnixLabs.Core.Text
1920
{
@@ -68,9 +69,7 @@ public override bool Equals(object? obj)
6869
/// <returns>A hash code for this instance.</returns>
6970
public override int GetHashCode()
7071
{
71-
return new HashCode()
72-
.AddItems(Value)
73-
.ToHashCode();
72+
return HashCode.Combine(Value.ComputeContentHashCode());
7473
}
7574
}
7675
}

OnixLabs.Core/Text/Base64.Empty.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2020-2021 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
17+
namespace OnixLabs.Core.Text
18+
{
19+
public readonly partial struct Base64
20+
{
21+
/// <summary>
22+
/// Gets an empty Base-64 value.
23+
/// </summary>
24+
public static readonly Base64 Empty;
25+
26+
/// <summary>
27+
/// Initializes static members of the <see cref="Base64"/> class.
28+
/// </summary>
29+
static Base64()
30+
{
31+
Empty = FromByteArray(Array.Empty<byte>());
32+
}
33+
}
34+
}

OnixLabs.Core/Text/Base64.Equatable.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System;
1616
using System.Linq;
17+
using OnixLabs.Core.Linq;
1718

1819
namespace OnixLabs.Core.Text
1920
{
@@ -67,9 +68,7 @@ public override bool Equals(object? obj)
6768
/// <returns>A hash code for this instance.</returns>
6869
public override int GetHashCode()
6970
{
70-
return new HashCode()
71-
.AddItems(Value)
72-
.ToHashCode();
71+
return HashCode.Combine(Value.ComputeContentHashCode());
7372
}
7473
}
7574
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2020-2021 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
17+
namespace OnixLabs.Security.Cryptography
18+
{
19+
public readonly partial struct DigitalSignature
20+
{
21+
/// <summary>
22+
/// Gets an empty digital signature value.
23+
/// </summary>
24+
public static readonly DigitalSignature Empty;
25+
26+
/// <summary>
27+
/// Initializes static members of the <see cref="DigitalSignature"/> class.
28+
/// </summary>
29+
static DigitalSignature()
30+
{
31+
Empty = FromByteArray(Array.Empty<byte>());
32+
}
33+
}
34+
}

OnixLabs.Security.Cryptography/DigitalSignature.Equatable.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
using System;
1616
using System.Linq;
17-
using OnixLabs.Core;
17+
using OnixLabs.Core.Linq;
1818

1919
namespace OnixLabs.Security.Cryptography
2020
{
@@ -68,9 +68,7 @@ public override bool Equals(object? obj)
6868
/// <returns>A hash code for this instance.</returns>
6969
public override int GetHashCode()
7070
{
71-
return new HashCode()
72-
.AddItems(Value)
73-
.ToHashCode();
71+
return HashCode.Combine(Value.ComputeContentHashCode());
7472
}
7573
}
7674
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2020-2021 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
17+
namespace OnixLabs.Security.Cryptography
18+
{
19+
public readonly partial struct Hash
20+
{
21+
/// <summary>
22+
/// Gets an empty hash value.
23+
/// </summary>
24+
public static readonly Hash Empty;
25+
26+
/// <summary>
27+
/// Initializes static members of the <see cref="Hash"/> class.
28+
/// </summary>
29+
static Hash()
30+
{
31+
Empty = FromByteArray(Array.Empty<byte>(), HashAlgorithmType.Unknown);
32+
}
33+
}
34+
}

OnixLabs.Security.Cryptography/Hash.Equatable.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
using System;
1616
using System.Linq;
17-
using OnixLabs.Core;
17+
using OnixLabs.Core.Linq;
1818

1919
namespace OnixLabs.Security.Cryptography
2020
{
@@ -49,7 +49,7 @@ namespace OnixLabs.Security.Cryptography
4949
/// <returns>true if the object is equal to this instance; otherwise, false.</returns>
5050
public bool Equals(Hash other)
5151
{
52-
return other.AlgorithmType == AlgorithmType
52+
return other.AlgorithmType == AlgorithmType
5353
&& other.Value.SequenceEqual(Value);
5454
}
5555

@@ -69,10 +69,7 @@ public override bool Equals(object? obj)
6969
/// <returns>A hash code for this instance.</returns>
7070
public override int GetHashCode()
7171
{
72-
return new HashCode()
73-
.AddItem(AlgorithmType)
74-
.AddItems(Value)
75-
.ToHashCode();
72+
return HashCode.Combine(AlgorithmType, Value.ComputeContentHashCode());
7673
}
7774
}
7875
}

0 commit comments

Comments
 (0)