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
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# top-most EditorConfig file
root = true

[*.cs]
end_of_line = lf
indent_style = space
indent_size = 4

# IDE0049: Use framework type
dotnet_style_predefined_type_for_locals_parameters_members = true
dotnet_style_predefined_type_for_member_access = true

# IDE0008: Use explicit type
csharp_style_var_when_type_is_apparent = true
csharp_style_var_for_built_in_types = true
csharp_style_var_elsewhere = true

# IDE0009: Member access should be qualified.
dotnet_style_qualification_for_method = false
dotnet_style_qualification_for_event = false
dotnet_style_qualification_for_field = false
dotnet_style_qualification_for_property = false

# IDE0058: Expression value is never used
csharp_style_unused_value_expression_statement_preference = discard_variable:none
dotnet_diagnostic.IDE0058.severity = none
21 changes: 4 additions & 17 deletions Hashids.net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,33 @@ VisualStudioVersion = 16.0.29324.140
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A6015393-39EA-44E3-BF0A-37D2BC5CC874}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
LICENSE.txt = LICENSE.txt
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hashids.net", "src\Hashids.net\Hashids.net.csproj", "{4802CAD5-1B10-4C3F-9333-B80664A9A4FC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hashids.net", "src\Hashids.net\Hashids.net.csproj", "{4802CAD5-1B10-4C3F-9333-B80664A9A4FC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hashids.net.test", "test\Hashids.net.test\Hashids.net.test.csproj", "{3BB2139F-2788-4B8C-9A2E-9F35BFCD3EBB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hashids.net.test", "test\Hashids.net.test\Hashids.net.test.csproj", "{3BB2139F-2788-4B8C-9A2E-9F35BFCD3EBB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hashids.net.benchmark", "test\Hashids.net.benchmark\Hashids.net.benchmark.csproj", "{5A9F0EB0-FFE0-41BF-8A8D-11CD23B283B7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hashids.net.benchmark", "test\Hashids.net.benchmark\Hashids.net.benchmark.csproj", "{5A9F0EB0-FFE0-41BF-8A8D-11CD23B283B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
NET40|Any CPU = NET40|Any CPU
NET45|Any CPU = NET45|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4802CAD5-1B10-4C3F-9333-B80664A9A4FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4802CAD5-1B10-4C3F-9333-B80664A9A4FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4802CAD5-1B10-4C3F-9333-B80664A9A4FC}.NET40|Any CPU.ActiveCfg = Debug|Any CPU
{4802CAD5-1B10-4C3F-9333-B80664A9A4FC}.NET40|Any CPU.Build.0 = Debug|Any CPU
{4802CAD5-1B10-4C3F-9333-B80664A9A4FC}.NET45|Any CPU.ActiveCfg = Debug|Any CPU
{4802CAD5-1B10-4C3F-9333-B80664A9A4FC}.NET45|Any CPU.Build.0 = Debug|Any CPU
{4802CAD5-1B10-4C3F-9333-B80664A9A4FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4802CAD5-1B10-4C3F-9333-B80664A9A4FC}.Release|Any CPU.Build.0 = Release|Any CPU
{3BB2139F-2788-4B8C-9A2E-9F35BFCD3EBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3BB2139F-2788-4B8C-9A2E-9F35BFCD3EBB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BB2139F-2788-4B8C-9A2E-9F35BFCD3EBB}.NET40|Any CPU.ActiveCfg = Debug|Any CPU
{3BB2139F-2788-4B8C-9A2E-9F35BFCD3EBB}.NET40|Any CPU.Build.0 = Debug|Any CPU
{3BB2139F-2788-4B8C-9A2E-9F35BFCD3EBB}.NET45|Any CPU.ActiveCfg = Debug|Any CPU
{3BB2139F-2788-4B8C-9A2E-9F35BFCD3EBB}.NET45|Any CPU.Build.0 = Debug|Any CPU
{3BB2139F-2788-4B8C-9A2E-9F35BFCD3EBB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BB2139F-2788-4B8C-9A2E-9F35BFCD3EBB}.Release|Any CPU.Build.0 = Release|Any CPU
{5A9F0EB0-FFE0-41BF-8A8D-11CD23B283B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A9F0EB0-FFE0-41BF-8A8D-11CD23B283B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A9F0EB0-FFE0-41BF-8A8D-11CD23B283B7}.NET40|Any CPU.ActiveCfg = Debug|Any CPU
{5A9F0EB0-FFE0-41BF-8A8D-11CD23B283B7}.NET40|Any CPU.Build.0 = Debug|Any CPU
{5A9F0EB0-FFE0-41BF-8A8D-11CD23B283B7}.NET45|Any CPU.ActiveCfg = Debug|Any CPU
{5A9F0EB0-FFE0-41BF-8A8D-11CD23B283B7}.NET45|Any CPU.Build.0 = Debug|Any CPU
{5A9F0EB0-FFE0-41BF-8A8D-11CD23B283B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A9F0EB0-FFE0-41BF-8A8D-11CD23B283B7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
27 changes: 25 additions & 2 deletions src/Hashids.net/ArrayExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace HashidsNet
{
Expand All @@ -12,14 +14,22 @@ public static T[] SubArray<T>(this T[] array, int index)

public static T[] SubArray<T>(this T[] array, int index, int length)
{
if (index == 0 && length == array.Length) return array;
if (length == 0) return Array.Empty<T>();

var subarray = new T[length];
Array.Copy(array, index, subarray, 0, length);
return subarray;
}

public static T[] Append<T>(this T[] array, T[] appendArray, int index, int length)
{
var newArray = new T[array.Length + length - index];
if (length == 0) return array;

int newLength = array.Length + length - index;
if (newLength == 0) return Array.Empty<T>();

var newArray = new T[newLength];
Array.Copy(array, 0, newArray, 0, array.Length);
Array.Copy(appendArray, index, newArray, array.Length, length - index);
return newArray;
Expand All @@ -44,5 +54,18 @@ public static void ReturnToPool<T>(this T[] array)

ArrayPool<T>.Shared.Return(array);
}

#if NETCOREAPP3_1_OR_GREATER
/// <remarks>This method exists because <see cref="ReadOnlySpan{T}"/> does not implement <see cref="IEnumerable{T}"/> and using <c>.AsEnumerable()</c> will cause boxing.</remarks>
public static bool Any<T>(this ReadOnlySpan<T> span, Func<T,bool> predicate)
{
for(int i = 0; i < span.Length; i++)
{
if(predicate(span[i])) return true;
}

return false;
}
#endif
}
}
8 changes: 5 additions & 3 deletions src/Hashids.net/Hashids.Obsolete.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System;
using System.ComponentModel;

namespace HashidsNet
{
/// <summary>
/// Generate YouTube-like hashes from one or many numbers. Use hashids when you do not want to expose your database ids to the user.
/// </summary>
public partial class Hashids : IHashids
{
/// <summary>
/// Encodes the provided numbers into a hash.
/// </summary>
[Obsolete("Use 'Encode' instead. The method was renamed to better explain what it actually does.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual string Encrypt(params int[] numbers)
{
return Encode(numbers);
Expand All @@ -20,6 +19,7 @@ public virtual string Encrypt(params int[] numbers)
/// Encrypts the provided hex-string to a hash.
/// </summary>
[Obsolete("Use 'EncodeHex' instead. The method was renamed to better explain what it actually does.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual string EncryptHex(string hex)
{
return EncodeHex(hex);
Expand All @@ -29,6 +29,7 @@ public virtual string EncryptHex(string hex)
/// Decodes the provided hash into an array of numbers.
/// </summary>
[Obsolete("Use 'Decode' instead. Method was renamed to better explain what it actually does.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual int[] Decrypt(string hash)
{
return Decode(hash);
Expand All @@ -38,6 +39,7 @@ public virtual int[] Decrypt(string hash)
/// Decodes the provided hash to a hex-string.
/// </summary>
[Obsolete("Use 'DecodeHex' instead. The method was renamed to better explain what it actually does.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual string DecryptHex(string hash)
{
return DecodeHex(hash);
Expand Down
Loading