-
Notifications
You must be signed in to change notification settings - Fork 1k
[Move] Part-5 Classes into Different Library - Neo.Extensions
#3409
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
Merged
shargon
merged 42 commits into
neo-project:master
from
cschuchardt88:rebuild/the-split-5
Sep 28, 2024
Merged
Changes from 29 commits
Commits
Show all changes
42 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 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 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 e644bd3
Added `tests` for `PART-4`
cschuchardt88 79a3578
Merge branch 'rebuild/the-split-4' into rebuild/the-split-5
cschuchardt88 6fa0fda
Added `tests` for `PART-5`
cschuchardt88 1640c9b
merge master
cschuchardt88 da0f201
Made changes and fixes
cschuchardt88 fffe338
Merge branch 'master' into rebuild/the-split-5
cschuchardt88 58f46ea
Fixes
cschuchardt88 6676e1f
Merge branch 'master' into rebuild/the-split-5
c30a0db
Apply suggestions from code review
shargon 9b009dd
Update tests/Neo.Extensions.Tests/UT_StringExtensions.cs
shargon adefc36
Merge branch 'master' into rebuild/the-split-5
shargon 4c8e13b
Merge branch 'master' into rebuild/the-split-5
3e5a0dd
@shagron review changes
cschuchardt88 17e0c3b
Merge branch 'rebuild/the-split-5' of https://github.com/cschuchardt8…
cschuchardt88 c1dd9f3
formating
cschuchardt88 1e877bf
Moved `UnsafeData` tests to `UT_UnsafeData`
cschuchardt88 9fe3ba9
Merge branch 'master' into rebuild/the-split-5
cschuchardt88 9e3ce91
Formating
cschuchardt88 4d4dc97
Merge branch 'master' into rebuild/the-split-5
shargon f60851d
Merge branch 'master' into rebuild/the-split-5
cschuchardt88 db012ce
Merge branch 'master' into rebuild/the-split-5
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 hidden or 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 hidden or 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 hidden or 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,74 @@ | ||
| // Copyright (C) 2015-2024 The Neo Project. | ||
| // | ||
| // ICollectionExtensions.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 Neo.IO; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace Neo.Extensions | ||
| { | ||
| public static class ICollectionExtensions | ||
| { | ||
| /// <summary> | ||
| /// Gets the size of the specified array encoded in variable-length encoding. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of the array element.</typeparam> | ||
| /// <param name="value">The specified array.</param> | ||
| /// <returns>The size of the array.</returns> | ||
| public static int GetVarSize<T>(this IReadOnlyCollection<T> value) | ||
| { | ||
| int value_size; | ||
| var t = typeof(T); | ||
| if (typeof(ISerializable).IsAssignableFrom(t)) | ||
| { | ||
| value_size = value.OfType<ISerializable>().Sum(p => p.Size); | ||
| } | ||
| else if (t.GetTypeInfo().IsEnum) | ||
| { | ||
| int element_size; | ||
| var u = t.GetTypeInfo().GetEnumUnderlyingType(); | ||
| if (u == typeof(sbyte) || u == typeof(byte)) | ||
| element_size = 1; | ||
| else if (u == typeof(short) || u == typeof(ushort)) | ||
| element_size = 2; | ||
| else if (u == typeof(int) || u == typeof(uint)) | ||
| element_size = 4; | ||
| else //if (u == typeof(long) || u == typeof(ulong)) | ||
| element_size = 8; | ||
| value_size = value.Count * element_size; | ||
| } | ||
| else | ||
| { | ||
| value_size = value.Count * Marshal.SizeOf<T>(); | ||
| } | ||
| return UnsafeData.GetVarSize(value.Count) + value_size; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Converts an <see cref="ISerializable"/> array to a byte array. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of the array element.</typeparam> | ||
| /// <param name="value">The <see cref="ISerializable"/> array to be converted.</param> | ||
| /// <returns>The converted byte array.</returns> | ||
| public static byte[] ToByteArray<T>(this IReadOnlyCollection<T> value) | ||
| where T : ISerializable | ||
| { | ||
| using MemoryStream ms = new(); | ||
| using BinaryWriter writer = new(ms, Utility.StrictUTF8, true); | ||
| writer.Write(value); | ||
| writer.Flush(); | ||
| return ms.ToArray(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,60 @@ | ||
| // Copyright (C) 2015-2024 The Neo Project. | ||
| // | ||
| // MemoryExtensions.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 Neo.IO; | ||
| using System; | ||
| using System.Reflection; | ||
|
|
||
| namespace Neo.Extensions | ||
| { | ||
| public static class MemoryExtensions | ||
| { | ||
| /// <summary> | ||
| /// Converts a byte array to an <see cref="ISerializable"/> object. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type to convert to.</typeparam> | ||
| /// <param name="value">The byte array to be converted.</param> | ||
| /// <returns>The converted <see cref="ISerializable"/> object.</returns> | ||
| public static T AsSerializable<T>(this ReadOnlyMemory<byte> value) | ||
| where T : ISerializable, new() | ||
| { | ||
| if (value.IsEmpty) throw new FormatException(); | ||
| MemoryReader reader = new(value); | ||
| return reader.ReadSerializable<T>(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Converts a byte array to an <see cref="ISerializable"/> object. | ||
| /// </summary> | ||
| /// <param name="value">The byte array to be converted.</param> | ||
| /// <param name="type">The type to convert to.</param> | ||
| /// <returns>The converted <see cref="ISerializable"/> object.</returns> | ||
| public static ISerializable AsSerializable(this ReadOnlyMemory<byte> value, Type type) | ||
| { | ||
| if (!typeof(ISerializable).GetTypeInfo().IsAssignableFrom(type)) | ||
| throw new InvalidCastException(); | ||
| var serializable = (ISerializable)Activator.CreateInstance(type); | ||
| MemoryReader reader = new(value); | ||
| serializable.Deserialize(ref reader); | ||
| return serializable; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the size of the specified array encoded in variable-length encoding. | ||
| /// </summary> | ||
| /// <param name="value">The specified array.</param> | ||
| /// <returns>The size of the array.</returns> | ||
| public static int GetVarSize(this ReadOnlyMemory<byte> value) | ||
| { | ||
| return UnsafeData.GetVarSize(value.Length) + value.Length; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.