-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Move]
Part-7 Classes into Different Library - Neo.Extensions
#3446
Merged
NGDAdmin
merged 39 commits into
neo-project:master
from
cschuchardt88:rebuild/the-split-7
Nov 29, 2024
Merged
Changes from 32 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
bf93412
Part-1 `Neo.IO` - move
cschuchardt88 4d08154
Part-2
cschuchardt88 597c9ca
Merge branch 'master' into rebuild/the-split-2
cschuchardt88 9881579
Added `BigInteger` to `Neo.Extensions`
cschuchardt88 8779151
Found more `BigInteger`
cschuchardt88 ed34707
Added `ByteArray` to `Neo.Extensions`
cschuchardt88 5b12304
Added `DateTime` Extensions to `Neo.Extensions`
cschuchardt88 0f6627a
Added `HashSetExtensions`, `HashSetExtensions2`, `IpAddressExtensions…
cschuchardt88 95f8a2d
Merge branch 'master' into rebuild/the-split-4
cschuchardt88 721ce58
Added `ICollection`, `Memory`, `String`, `Unsafe` extensions
cschuchardt88 129a32f
Adding `using`
cschuchardt88 397cc1f
dotnet format
cschuchardt88 a127386
Added more Extensions
cschuchardt88 9a84436
Move some methods
cschuchardt88 dbbf5b3
Merge branch 'master' into rebuild/the-split-2
shargon b64435b
Added Tests
cschuchardt88 583e610
Merge branch 'rebuild/the-split-2' of https://github.com/cschuchardt8…
cschuchardt88 6a50385
Merge branch 'rebuild/the-split-2' into rebuild/the-split-3
cschuchardt88 f381b89
Merge branch 'rebuild/the-split-3' into rebuild/the-split-4
cschuchardt88 6261f70
Merge branch 'rebuild/the-split-4' into rebuild/the-split-5
cschuchardt88 4a0fb7a
Merge branch 'rebuild/the-split-5' into rebuild/the-split-6
cschuchardt88 58f7fee
Added `tests` from `Part-2`
cschuchardt88 7f74300
Merge branch 'rebuild/the-split-3' into rebuild/the-split-4
cschuchardt88 c790166
Merge branch 'rebuild/the-split-4' into rebuild/the-split-5
cschuchardt88 26d0515
Merge branch 'rebuild/the-split-5' into rebuild/the-split-6
cschuchardt88 e644bd3
Added `tests` for `PART-4`
cschuchardt88 79a3578
Merge branch 'rebuild/the-split-4' into rebuild/the-split-5
cschuchardt88 00ce5ae
Merge branch 'rebuild/the-split-5' into rebuild/the-split-6
cschuchardt88 6fa0fda
Added `tests` for `PART-5`
cschuchardt88 708ce84
Merge branch 'rebuild/the-split-5' into rebuild/the-split-6
cschuchardt88 bb9992e
Merge Master
cschuchardt88 ff3c158
Added the `Part` 7
cschuchardt88 d761585
Merge Master into `the-split-7`
cschuchardt88 9ecd77f
revert `OrCondition.cs`
cschuchardt88 15c092d
revert `OrCondition.cs`
cschuchardt88 b333474
Merge branch 'master' into rebuild/the-split-7
shargon 0b24c62
Update tests/Neo.Extensions.Tests/UT_BigIntegerExtensions.cs
shargon b241941
Merge branch 'master' into rebuild/the-split-7
shargon 8e1ff35
Merge branch 'master' into rebuild/the-split-7
Jim8y File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// AssemblyExtensions.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using System.Reflection; | ||
|
||
namespace Neo.Extensions | ||
{ | ||
public static class AssemblyExtensions | ||
{ | ||
public static string GetVersion(this Assembly assembly) | ||
{ | ||
return assembly.GetName().Version!.ToString(3); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// HashSetExtensions.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Neo.Extensions | ||
{ | ||
public static class HashSetExtensions | ||
{ | ||
public static void Remove<T>(this HashSet<T> set, ISet<T> other) | ||
{ | ||
if (set.Count > other.Count) | ||
{ | ||
set.ExceptWith(other); | ||
} | ||
else | ||
{ | ||
set.RemoveWhere(u => other.Contains(u)); | ||
} | ||
} | ||
|
||
public static void Remove<T, V>(this HashSet<T> set, IReadOnlyDictionary<T, V> other) | ||
{ | ||
if (set.Count > other.Count) | ||
{ | ||
set.ExceptWith(other.Keys); | ||
} | ||
else | ||
{ | ||
set.RemoveWhere(u => other.ContainsKey(u)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// DateTimeExtensions.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using System; | ||
|
||
namespace Neo.Extensions | ||
{ | ||
public static class DateTimeExtensions | ||
{ | ||
/// <summary> | ||
/// Converts a <see cref="DateTime"/> to timestamp. | ||
/// </summary> | ||
/// <param name="time">The <see cref="DateTime"/> to convert.</param> | ||
/// <returns>The converted timestamp.</returns> | ||
public static uint ToTimestamp(this DateTime time) | ||
{ | ||
return (uint)new DateTimeOffset(time.ToUniversalTime()).ToUnixTimeSeconds(); | ||
} | ||
|
||
/// <summary> | ||
/// Converts a <see cref="DateTime"/> to timestamp in milliseconds. | ||
/// </summary> | ||
/// <param name="time">The <see cref="DateTime"/> to convert.</param> | ||
/// <returns>The converted timestamp.</returns> | ||
public static ulong ToTimestampMS(this DateTime time) | ||
{ | ||
return (ulong)new DateTimeOffset(time.ToUniversalTime()).ToUnixTimeMilliseconds(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// IpAddressExtensions.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using System.Net; | ||
|
||
namespace Neo.Extensions | ||
{ | ||
public static class IpAddressExtensions | ||
{ | ||
/// <summary> | ||
/// Checks if address is IPv4 Mapped to IPv6 format, if so, Map to IPv4. | ||
/// Otherwise, return current address. | ||
/// </summary> | ||
public static IPAddress UnMap(this IPAddress address) | ||
{ | ||
if (address.IsIPv4MappedToIPv6) | ||
address = address.MapToIPv4(); | ||
return address; | ||
} | ||
|
||
/// <summary> | ||
/// Checks if IPEndPoint is IPv4 Mapped to IPv6 format, if so, unmap to IPv4. | ||
/// Otherwise, return current endpoint. | ||
/// </summary> | ||
public static IPEndPoint UnMap(this IPEndPoint endPoint) | ||
{ | ||
if (!endPoint.Address.IsIPv4MappedToIPv6) | ||
return endPoint; | ||
return new IPEndPoint(endPoint.Address.UnMap(), endPoint.Port); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// RandomExtensions.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using System; | ||
using System.Numerics; | ||
|
||
namespace Neo.Extensions | ||
{ | ||
public static class RandomExtensions | ||
{ | ||
public static BigInteger NextBigInteger(this Random rand, int sizeInBits) | ||
{ | ||
if (sizeInBits < 0) | ||
throw new ArgumentException("sizeInBits must be non-negative"); | ||
if (sizeInBits == 0) | ||
return 0; | ||
Span<byte> b = stackalloc byte[sizeInBits / 8 + 1]; | ||
rand.NextBytes(b); | ||
if (sizeInBits % 8 == 0) | ||
b[^1] = 0; | ||
else | ||
b[^1] &= (byte)((1 << sizeInBits % 8) - 1); | ||
return new BigInteger(b); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// StringExtensions.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using System; | ||
using System.Globalization; | ||
|
||
namespace Neo.Extensions | ||
{ | ||
public static class StringExtensions | ||
{ | ||
/// <summary> | ||
/// Converts a hex <see cref="string"/> to byte array. | ||
/// </summary> | ||
/// <param name="value">The hex <see cref="string"/> to convert.</param> | ||
/// <returns>The converted byte array.</returns> | ||
public static byte[] HexToBytes(this string value) | ||
{ | ||
if (value == null || value.Length == 0) | ||
return []; | ||
if (value.Length % 2 == 1) | ||
throw new FormatException(); | ||
var result = new byte[value.Length / 2]; | ||
for (var i = 0; i < result.Length; i++) | ||
result[i] = byte.Parse(value.Substring(i * 2, 2), NumberStyles.AllowHexSpecifier); | ||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the size of the specified <see cref="string"/> encoded in variable-length encoding. | ||
/// </summary> | ||
/// <param name="value">The specified <see cref="string"/>.</param> | ||
/// <returns>The size of the <see cref="string"/>.</returns> | ||
public static int GetVarSize(this string value) | ||
{ | ||
var size = Utility.StrictUTF8.GetByteCount(value); | ||
return UnsafeData.GetVarSize(size) + size; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// UnsafeData.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
namespace Neo.Extensions | ||
{ | ||
public static class UnsafeData | ||
{ | ||
/// <summary> | ||
/// Gets the size of variable-length of the data. | ||
/// </summary> | ||
/// <param name="value">The length of the data.</param> | ||
/// <returns>The size of variable-length of the data.</returns> | ||
public static int GetVarSize(int value) | ||
{ | ||
if (value < 0xFD) | ||
return sizeof(byte); | ||
else if (value <= 0xFFFF) | ||
return sizeof(byte) + sizeof(ushort); | ||
else | ||
return sizeof(byte) + sizeof(uint); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
( Does
set.Remove(other)
have any difference fromset.ExceptWith(other)
, even whenset.Count <= other.Count
? )There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No clue. I'm just moving the method to appropriate namespaces or libraries.