From 2b25fff1842924d47118e8e1009cf358326cb048 Mon Sep 17 00:00:00 2001 From: Alan Brault Date: Wed, 15 Nov 2023 11:22:22 -0500 Subject: [PATCH] refactor: change serialization behavior of Cuid Signed-off-by: Alan Brault --- .editorconfig | 70 ++++++++-- .github/workflows/ci.yaml | 8 +- .github/workflows/release.yaml | 6 +- cuid.net.sln | 1 + global.json | 2 +- renovate.json | 70 +++++----- .../Abstractions/FingerprintVersion.cs | 2 +- src/cuid.net/Cuid.cs | 121 ++++++++++-------- src/cuid.net/Cuid2.cs | 18 +-- src/cuid.net/Extensions/StringExtensions.cs | 6 +- src/cuid.net/Fingerprint.cs | 37 +++--- src/cuid.net/Obsoletions.cs | 2 +- src/cuid.net/Resources/Resources.Designer.cs | 55 +++----- src/cuid.net/Resources/Resources.resx | 13 +- .../Json/Converters/CuidConverter.cs | 2 +- src/cuid.net/Utils.cs | 6 +- src/cuid.net/cuid.net.csproj | 35 ++--- src/cuid.net/packages.lock.json | 6 +- ....Cuid_NoBreakingChanges_Async.verified.txt | 3 +- tests/cuid.net.tests/ApiFacts.cs | 3 +- tests/cuid.net.tests/Cuid2Facts.cs | 6 +- tests/cuid.net.tests/CuidFacts.cs | 13 +- tests/cuid.net.tests/Usings.cs | 2 +- tests/cuid.net.tests/cuid.net.tests.csproj | 14 +- 24 files changed, 279 insertions(+), 222 deletions(-) diff --git a/.editorconfig b/.editorconfig index d5e3354..5d9df2a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,11 +1,5 @@ -root = true # Remove the line below if you want to inherit .editorconfig settings from higher directories - -# All files -[*] - -guidelines = 120 -guidelines_style = 1px solid 40ff0000 +root = true # C# files [*.cs] @@ -18,8 +12,8 @@ indent_style = tab tab_width = 4 # New line preferences -end_of_line = crlf -insert_final_newline = false +end_of_line = lf +insert_final_newline = true #### .NET Coding Conventions #### @@ -68,9 +62,9 @@ dotnet_code_quality_unused_parameters = all:suggestion #### C# Coding Conventions #### # var preferences -csharp_style_var_elsewhere = false:error -csharp_style_var_for_built_in_types = false:error -csharp_style_var_when_type_is_apparent = false:error +csharp_style_var_elsewhere = false:warning +csharp_style_var_for_built_in_types = false:warning +csharp_style_var_when_type_is_apparent = false:warning # Expression-bodied members csharp_style_expression_bodied_accessors = true @@ -115,7 +109,6 @@ csharp_new_line_before_else = true csharp_new_line_before_finally = true csharp_new_line_before_members_in_anonymous_types = true csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_open_brace = all csharp_new_line_between_query_expression_clauses = true # Indentation preferences @@ -153,3 +146,54 @@ csharp_space_between_square_brackets = false # Wrapping preferences csharp_preserve_single_line_blocks = true csharp_preserve_single_line_statements = true + +#### Resharper Formatting Rules #### + +resharper_csharp_accessor_declaration_braces = next_line +resharper_csharp_accessor_owner_declaration_braces = next_line +resharper_csharp_align_first_arg_by_paren = true +resharper_csharp_align_linq_query = true +resharper_csharp_align_multiline_argument = true +resharper_csharp_align_multiline_array_and_object_initializer = false +resharper_csharp_align_multiline_binary_expressions_chain = true +resharper_csharp_align_multiline_binary_patterns = true +resharper_csharp_align_multiline_calls_chain = true +resharper_csharp_align_multiline_expression = true +resharper_csharp_align_multiline_extends_list = true +resharper_csharp_align_multiline_parameter = true +resharper_csharp_align_multiline_property_pattern = true +resharper_csharp_align_multiline_statement_conditions = true +resharper_csharp_align_multiline_switch_expression = false +resharper_csharp_align_multiple_declaration = true +resharper_csharp_align_multline_type_parameter_constrains = true +resharper_csharp_align_multline_type_parameter_list = true +resharper_csharp_align_tuple_components = true +resharper_csharp_alignment_tab_fill_style = optimal_fill +resharper_csharp_allow_far_alignment = true +resharper_csharp_brace_style = next_line +resharper_csharp_case_block_braces = next_line +resharper_csharp_continuous_indent_multiplier = 1 +resharper_csharp_indent_anonymous_method_block = true +resharper_csharp_indent_braces_inside_statement_conditions = true +resharper_csharp_indent_inside_namespace = true +resharper_csharp_indent_nested_fixed_stmt = false +resharper_csharp_indent_nested_for_stmt = false +resharper_csharp_indent_nested_foreach_stmt = false +resharper_csharp_indent_nested_lock_stmt = false +resharper_csharp_indent_nested_usings_stmt = false +resharper_csharp_indent_nested_while_stmt = false +resharper_csharp_indent_preprocessor_if = no_indent +resharper_csharp_indent_preprocessor_other = usual_indent +resharper_csharp_indent_preprocessor_region = no_indent +resharper_csharp_indent_type_constraints = true +resharper_csharp_initializer_braces = next_line +resharper_csharp_invocable_declaration_braces = next_line +resharper_csharp_keep_existing_initializer_arrangement = false +resharper_csharp_max_initializer_elements_on_line = 1 +resharper_csharp_other_braces = next_line +resharper_csharp_outdent_binary_ops = true +resharper_csharp_outdent_binary_pattern_ops = true +resharper_csharp_outdent_dots = true +resharper_csharp_place_simple_initializer_on_single_line = true +resharper_csharp_type_declaration_braces = next_line +resharper_csharp_wrap_object_and_collection_initializer_style = chop_always \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index dccecae..3777523 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,7 +6,7 @@ on: - main paths-ignore: - '**.md' - - '**/renovate.json' + - '**/renovate.json' - '.github/workflows/release.yaml' pull_request: paths-ignore: @@ -20,7 +20,7 @@ jobs: env: DOTNET_CLI_TELEMETRY_OPTOUT: true DOTNET_NOLOGO: true - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - name: Checkout uses: actions/checkout@v4 @@ -37,7 +37,7 @@ jobs: with: global-json-file: global.json - name: Build - run: dotnet build -c release + run: dotnet build -c release - name: Test run: | dotnet test -c release --no-restore --no-build \ @@ -58,5 +58,5 @@ jobs: uses: codacy/codacy-coverage-reporter-action@v1 with: project-token: ${{ secrets.CODACY_TOKEN }} - coverage-reports: ${{ runner.temp }}/coverage.opencover.*.xml + coverage-reports: ${{ runner.temp }}/coverage.opencover.xml \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e0cdefc..3adf2ff 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -5,7 +5,7 @@ on: push: tags: - '*' - + jobs: build: name: Build, Analyze & Test @@ -14,7 +14,7 @@ jobs: DOTNET_CLI_TELEMETRY_OPTOUT: true DOTNET_NOLOGO: true GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} steps: - name: Checkout uses: actions/checkout@v4 @@ -25,7 +25,7 @@ jobs: with: path: ~/.nuget/packages key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} - restore-keys: ${{ runner.os}}-nuget + restore-keys: ${{ runner.os}}-nuget - name: Install .NET SDK uses: actions/setup-dotnet@v3 with: diff --git a/cuid.net.sln b/cuid.net.sln index 0d96cdc..4a8be01 100644 --- a/cuid.net.sln +++ b/cuid.net.sln @@ -23,6 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Directory.Build.props = Directory.Build.props .gitignore = .gitignore global.json = global.json + .editorconfig = .editorconfig EndProjectSection EndProject Global diff --git a/global.json b/global.json index d4e0b89..da113e4 100644 --- a/global.json +++ b/global.json @@ -2,6 +2,6 @@ "sdk": { "version": "8.0.0", "rollForward": "latestFeature", - "allowPrerelease": true + "allowPrerelease": false } } \ No newline at end of file diff --git a/renovate.json b/renovate.json index 454af4a..d861677 100644 --- a/renovate.json +++ b/renovate.json @@ -1,37 +1,37 @@ { - "extends": [ - "config:base", - ":disableDependencyDashboard", - ":gitSignOff" - ], - "assigneesFromCodeOwners": true, - "packageRules": [ - { - "matchPackagePatterns": [ - "*" - ], - "matchUpdateTypes": [ - "minor", - "patch" - ], - "groupName": "all non-major dependencies", - "groupSlug": "all-minor-patch", - "labels": [ - "dependencies" - ], - "automerge": true - }, - { - "matchPackagePatterns": [ - "*" - ], - "matchUpdateTypes": [ - "major" - ], - "labels": [ - "dependencies", - "breaking" - ] - } - ] + "extends": [ + "config:base", + ":disableDependencyDashboard", + ":gitSignOff" + ], + "assigneesFromCodeOwners": true, + "packageRules": [ + { + "matchPackagePatterns": [ + "*" + ], + "matchUpdateTypes": [ + "minor", + "patch" + ], + "groupName": "all non-major dependencies", + "groupSlug": "all-minor-patch", + "labels": [ + "dependencies" + ], + "automerge": true + }, + { + "matchPackagePatterns": [ + "*" + ], + "matchUpdateTypes": [ + "major" + ], + "labels": [ + "dependencies", + "breaking" + ] + } + ] } \ No newline at end of file diff --git a/src/cuid.net/Abstractions/FingerprintVersion.cs b/src/cuid.net/Abstractions/FingerprintVersion.cs index c559dc0..049079d 100644 --- a/src/cuid.net/Abstractions/FingerprintVersion.cs +++ b/src/cuid.net/Abstractions/FingerprintVersion.cs @@ -5,4 +5,4 @@ internal enum FingerprintVersion : byte None = 0, One = 1, Two = 2 -} \ No newline at end of file +} diff --git a/src/cuid.net/Cuid.cs b/src/cuid.net/Cuid.cs index 6f5467c..d0e90f8 100644 --- a/src/cuid.net/Cuid.cs +++ b/src/cuid.net/Cuid.cs @@ -4,9 +4,10 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Runtime.Serialization; using System.Text; using System.Text.Json.Serialization; +using System.Xml; +using System.Xml.Schema; using System.Xml.Serialization; using Abstractions; using Extensions; @@ -17,10 +18,9 @@ /// [StructLayout(LayoutKind.Sequential)] [JsonConverter(typeof(CuidConverter))] -[Serializable] [XmlRoot("cuid")] [Obsolete(Obsoletions.CuidMessage, DiagnosticId = Obsoletions.CuidDiagId)] -public readonly struct Cuid : IComparable, IComparable, IEquatable +public readonly struct Cuid : IComparable, IComparable, IEquatable, IXmlSerializable { /// /// A read-only instance of structure whose values are all zeros. @@ -58,7 +58,7 @@ public Cuid(string c) this = result.ToCuid(); } - + /// /// Initializes a new instance of the structure. /// @@ -240,17 +240,17 @@ public int CompareTo(object? obj) } return obj is Cuid other - ? CompareTo(other) - : throw new ArgumentException($"Object must be of type {nameof(Cuid)}"); + ? CompareTo(other) + : throw new ArgumentException($"Object must be of type {nameof(Cuid)}"); } /// public bool Equals(Cuid other) { return _counter == other._counter && - string.Equals(_fingerprint, other._fingerprint, StringComparison.OrdinalIgnoreCase) && - _random == other._random && - _timestamp == other._timestamp; + string.Equals(_fingerprint, other._fingerprint, StringComparison.OrdinalIgnoreCase) && + _random == other._random && + _timestamp == other._timestamp; } /// @@ -279,21 +279,37 @@ public override int GetHashCode() public override string ToString() { return string.Create(25, ( _t: _timestamp, _c: _counter, _f: _fingerprint, _r: _random ), (dest, buffer) => - { - Prefix.WriteTo(ref dest); - - Utils.Encode((ulong) buffer._t).WriteTo(ref dest); - - Utils.Encode(buffer._c) - .TrimPad(BlockSize) - .WriteTo(ref dest); - - buffer._f.WriteTo(ref dest); - - Utils.Encode(buffer._r) - .TrimPad(BlockSize * 2) - .WriteTo(ref dest); - }); + { + Prefix + .WriteTo(ref + dest); + + Utils + .Encode((ulong) + buffer + ._t) + .WriteTo(ref + dest); + + Utils + .Encode(buffer + ._c) + .TrimPad(BlockSize) + .WriteTo(ref + dest); + + buffer._f + .WriteTo(ref + dest); + + Utils + .Encode(buffer + ._r) + .TrimPad(BlockSize * + 2) + .WriteTo(ref + dest); + }); } private static bool IsAlphaNum(ReadOnlySpan input) @@ -335,28 +351,30 @@ private static bool TryParseCuid(ReadOnlySpan cuidString, bool throwExcept return true; } - // [ExcludeFromCodeCoverage] - // XmlSchema? IXmlSerializable.GetSchema() - // { - // return null; - // } - - // void IXmlSerializable.ReadXml(XmlReader reader) - // { - // reader.Read(); - // - // CuidResult result = new(); - // - // _ = TryParseCuid(reader.Value, true, ref result); - // - // this = new Cuid(result.ToCuid().ToString()); - // Unsafe.AsRef(ref this) = result.ToCuid(); - // } - - // void IXmlSerializable.WriteXml(XmlWriter writer) - // { - // writer.WriteString(ToString()); - // } + [ExcludeFromCodeCoverage] + XmlSchema? IXmlSerializable.GetSchema() + { + return null; + } + + unsafe void IXmlSerializable.ReadXml(XmlReader reader) + { + reader.Read(); + + CuidResult result = new(); + + _ = TryParseCuid(reader.Value, true, ref result); + + fixed ( Cuid* c = &this ) + { + *c = result.ToCuid(); + } + } + + void IXmlSerializable.WriteXml(XmlWriter writer) + { + writer.WriteString(ToString()); + } [SuppressMessage("ReSharper", "InconsistentNaming")] [StructLayout(LayoutKind.Explicit)] @@ -369,14 +387,15 @@ public readonly Cuid ToCuid() return Unsafe.As(ref Unsafe.AsRef(ref result)); } -#pragma warning disable CA1822 + #pragma warning disable CA1822 // ReSharper disable once MemberCanBeMadeStatic.Local internal readonly void SetFailure(string message) -#pragma warning restore CA1822 { throw new FormatException(message); } -#pragma warning disable S4487 + #pragma warning restore CA1822 + + #pragma warning disable S4487 [FieldOffset(8)] internal ulong _counter; [FieldOffset(0)] internal string _fingerprint; @@ -384,7 +403,7 @@ internal readonly void SetFailure(string message) [FieldOffset(16)] internal ulong _random; [FieldOffset(24)] internal long _timestamp; -#pragma warning restore S4487 + #pragma warning restore S4487 } private static class Context @@ -420,4 +439,4 @@ public uint Value } } } -} \ No newline at end of file +} diff --git a/src/cuid.net/Cuid2.cs b/src/cuid.net/Cuid2.cs index 75866c7..e9e559b 100644 --- a/src/cuid.net/Cuid2.cs +++ b/src/cuid.net/Cuid2.cs @@ -48,7 +48,7 @@ public Cuid2(int maxLength) if ( maxLength is < 4 or > 32 ) { throw new ArgumentOutOfRangeException(nameof(maxLength), - string.Format(Resources.Resources.Arg_Cuid2IntCtor, "4", "32")); + string.Format(Resources.Resources.Arg_Cuid2IntCtor, "4", "32")); } _maxLength = maxLength; @@ -85,10 +85,10 @@ public Cuid2(int maxLength) public bool Equals(Cuid2 other) { return _counter == other._counter && - _fingerprint.Equals(other._fingerprint) && - _prefix == other._prefix && - _random.Equals(other._random) && - _timestamp == other._timestamp; + _fingerprint.Equals(other._fingerprint) && + _prefix == other._prefix && + _random.Equals(other._random) && + _timestamp == other._timestamp; } /// @@ -110,18 +110,18 @@ public override int GetHashCode() public override string ToString() { Span buffer = stackalloc byte[16]; - + BinaryPrimitives.WriteInt64LittleEndian(buffer[..8], _timestamp); BinaryPrimitives.WriteUInt64LittleEndian(buffer[^8..], _counter); IncrementalHash.Initialize(HashAlgorithm.Sha512, out IncrementalHash state); - + IncrementalHash.Update(ref state, buffer); IncrementalHash.Update(ref state, _fingerprint); IncrementalHash.Update(ref state, _random); byte[] hash = IncrementalHash.Finalize(ref state); - + return _prefix + Utils.Encode(hash)[..( _maxLength - 1 )]; } @@ -146,4 +146,4 @@ private Counter() public ulong Value => Interlocked.Increment(ref _value); } -} \ No newline at end of file +} diff --git a/src/cuid.net/Extensions/StringExtensions.cs b/src/cuid.net/Extensions/StringExtensions.cs index 0cf2a67..b49ebe4 100644 --- a/src/cuid.net/Extensions/StringExtensions.cs +++ b/src/cuid.net/Extensions/StringExtensions.cs @@ -5,8 +5,8 @@ internal static class StringExtensions internal static string TrimPad(this string source, int size) { return string.IsNullOrWhiteSpace(source) - ? string.Empty - : source.PadLeft(9, '0')[^size..]; + ? string.Empty + : source.PadLeft(9, '0')[^size..]; } internal static void WriteTo(this string source, ref Span destination) @@ -19,4 +19,4 @@ private static void WriteToInternal(this ReadOnlySpan source, ref Span i + c); string result = string.Create(4, machineIdentifier, (dest, _) => - { - Environment.ProcessId.ToString(CultureInfo.InvariantCulture).TrimPad(2).WriteTo(ref dest); - machineIdentifier.ToString(CultureInfo.InvariantCulture).TrimPad(2).WriteTo(ref dest); - }); + { + Environment.ProcessId + .ToString(CultureInfo.InvariantCulture) + .TrimPad(2).WriteTo(ref dest); + machineIdentifier.ToString(CultureInfo.InvariantCulture) + .TrimPad(2).WriteTo(ref dest); + }); return Encoding.UTF8.GetBytes(result); } @@ -60,8 +63,8 @@ private static string GenerateSystemName() string hostname = Convert.ToHexString(bytes).ToUpperInvariant(); return OperatingSystem.IsWindows() - ? hostname[..15] // windows hostnames are limited to 15 characters - : hostname; + ? hostname[..15] // windows hostnames are limited to 15 characters + : hostname; } private static string RetrieveSystemName() @@ -70,8 +73,8 @@ private static string RetrieveSystemName() try { machineName = !string.IsNullOrWhiteSpace(Environment.MachineName) - ? Environment.MachineName - : GenerateSystemName(); + ? Environment.MachineName + : GenerateSystemName(); } catch ( InvalidOperationException ) { @@ -80,4 +83,4 @@ private static string RetrieveSystemName() return machineName; } -} \ No newline at end of file +} diff --git a/src/cuid.net/Obsoletions.cs b/src/cuid.net/Obsoletions.cs index 261ce75..1d094d0 100644 --- a/src/cuid.net/Obsoletions.cs +++ b/src/cuid.net/Obsoletions.cs @@ -4,4 +4,4 @@ internal static class Obsoletions { internal const string CuidDiagId = "VISLIB0001"; internal const string CuidMessage = "Cuid is deprecated and should not be used. Use Cuid2 instead."; -} \ No newline at end of file +} diff --git a/src/cuid.net/Resources/Resources.Designer.cs b/src/cuid.net/Resources/Resources.Designer.cs index c44977c..939c7c2 100644 --- a/src/cuid.net/Resources/Resources.Designer.cs +++ b/src/cuid.net/Resources/Resources.Designer.cs @@ -8,46 +8,35 @@ //------------------------------------------------------------------------------ namespace Visus.Cuid.Resources { - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + using System; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { - private static global::System.Resources.ResourceManager resourceMan; + private static System.Resources.ResourceManager resourceMan; - private static global::System.Globalization.CultureInfo resourceCulture; + private static System.Globalization.CultureInfo resourceCulture; - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Visus.Cuid.Resources.Resources", typeof(Resources).Assembly); + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Visus.Cuid.Resources.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -56,21 +45,15 @@ internal Resources() { } } - /// - /// Looks up a localized string similar to Value cannot be less than {0} or greater than {1}.. - /// - internal static string Arg_Cuid2IntCtor { + internal static string Format_CuidUnrecognized { get { - return ResourceManager.GetString("Arg_Cuid2IntCtor", resourceCulture); + return ResourceManager.GetString("Format_CuidUnrecognized", resourceCulture); } } - /// - /// Looks up a localized string similar to Unrecognized Cuid format.. - /// - internal static string Format_CuidUnrecognized { + internal static string Arg_Cuid2IntCtor { get { - return ResourceManager.GetString("Format_CuidUnrecognized", resourceCulture); + return ResourceManager.GetString("Arg_Cuid2IntCtor", resourceCulture); } } } diff --git a/src/cuid.net/Resources/Resources.resx b/src/cuid.net/Resources/Resources.resx index 000b944..7a91191 100644 --- a/src/cuid.net/Resources/Resources.resx +++ b/src/cuid.net/Resources/Resources.resx @@ -1,9 +1,10 @@  - + - + @@ -13,10 +14,14 @@ 1.3 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + Unrecognized Cuid format. diff --git a/src/cuid.net/Serialization/Json/Converters/CuidConverter.cs b/src/cuid.net/Serialization/Json/Converters/CuidConverter.cs index e1ade8b..9a44ba1 100644 --- a/src/cuid.net/Serialization/Json/Converters/CuidConverter.cs +++ b/src/cuid.net/Serialization/Json/Converters/CuidConverter.cs @@ -18,4 +18,4 @@ public override void Write(Utf8JsonWriter writer, Cuid value, JsonSerializerOpti { writer.WriteStringValue(value.ToString()); } -} \ No newline at end of file +} diff --git a/src/cuid.net/Utils.cs b/src/cuid.net/Utils.cs index a23a7af..179eed0 100644 --- a/src/cuid.net/Utils.cs +++ b/src/cuid.net/Utils.cs @@ -16,8 +16,8 @@ internal static class Utils internal static ulong Decode(ReadOnlySpan input) { return input.ToString() - .Select(s => s is >= '0' and <= '9' ? s - '0' : 10 + s - 'a') - .Aggregate((ulong) 0, (i, c) => ( i * Radix ) + (uint) c); + .Select(s => s is >= '0' and <= '9' ? s - '0' : 10 + s - 'a') + .Aggregate((ulong) 0, (i, c) => ( i * Radix ) + (uint) c); } internal static string Encode(ReadOnlySpan value) @@ -73,4 +73,4 @@ internal static byte[] GenerateRandom(int length = 8) { return RandomNumberGenerator.GetBytes(length); } -} \ No newline at end of file +} diff --git a/src/cuid.net/cuid.net.csproj b/src/cuid.net/cuid.net.csproj index 7bbd6bb..f734b02 100644 --- a/src/cuid.net/cuid.net.csproj +++ b/src/cuid.net/cuid.net.csproj @@ -6,15 +6,16 @@ enable Visus.Cuid Copyright (c) 2023 Visus Development Team + true - + cuid.net Visus embedded .NET implementation of collision-resistant ids - + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb true @@ -34,36 +35,36 @@ true - + all runtime; build; native; contentfiles; analyzers; buildtransitive - all - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive - + - + - - ResXFileCodeGenerator - Resources.Designer.cs - + + ResXFileCodeGenerator + Resources.Designer.cs + - - True - True - Resources.resx - + + True + True + Resources.resx + - + diff --git a/src/cuid.net/packages.lock.json b/src/cuid.net/packages.lock.json index 41b3e80..af7d3c5 100644 --- a/src/cuid.net/packages.lock.json +++ b/src/cuid.net/packages.lock.json @@ -10,9 +10,9 @@ }, "Microsoft.NET.ILLink.Tasks": { "type": "Direct", - "requested": "[8.0.0-rc.2.23479.6, )", - "resolved": "8.0.0-rc.2.23479.6", - "contentHash": "neRDuxVI/tdf5yz/rLyD1kP3DkWx8uHTvb1wcqbjDn4QQDHmYHwcuHBnVVPYtBzMFmlVNmJMa91weUEhHx2z5A==" + "requested": "[8.0.0, )", + "resolved": "8.0.0", + "contentHash": "B3etT5XQ2nlWkZGO2m/ytDYrOmSsQG1XNBaM6ZYlX5Ch/tDrMFadr0/mK6gjZwaQc55g+5+WZMw4Cz3m8VEF7g==" }, "Microsoft.SourceLink.GitHub": { "type": "Direct", diff --git a/tests/cuid.net.tests/ApiFacts.Cuid_NoBreakingChanges_Async.verified.txt b/tests/cuid.net.tests/ApiFacts.Cuid_NoBreakingChanges_Async.verified.txt index 852bb48..19e34bc 100644 --- a/tests/cuid.net.tests/ApiFacts.Cuid_NoBreakingChanges_Async.verified.txt +++ b/tests/cuid.net.tests/ApiFacts.Cuid_NoBreakingChanges_Async.verified.txt @@ -3,8 +3,7 @@ [System.Obsolete("Cuid is deprecated and should not be used. Use Cuid2 instead.", DiagnosticId="VISLIB0001")] [System.Text.Json.Serialization.JsonConverter(typeof(Visus.Cuid.Serialization.Json.Converters.CuidConverter))] [System.Xml.Serialization.XmlRoot("cuid")] - [System.Serializable] - public readonly struct Cuid : System.IComparable, System.IComparable, System.IEquatable + public readonly struct Cuid : System.IComparable, System.IComparable, System.IEquatable, System.Xml.Serialization.IXmlSerializable { public static readonly Visus.Cuid.Cuid Empty; public Cuid(string c) { } diff --git a/tests/cuid.net.tests/ApiFacts.cs b/tests/cuid.net.tests/ApiFacts.cs index 905085b..a2ca23c 100644 --- a/tests/cuid.net.tests/ApiFacts.cs +++ b/tests/cuid.net.tests/ApiFacts.cs @@ -3,7 +3,6 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using PublicApiGenerator; -using Visus.Cuid; [ExcludeFromCodeCoverage] [UsesVerify] @@ -23,4 +22,4 @@ public async Task Cuid_NoBreakingChanges_Async() await Verify(api); } -} \ No newline at end of file +} diff --git a/tests/cuid.net.tests/Cuid2Facts.cs b/tests/cuid.net.tests/Cuid2Facts.cs index 4f2b55f..a87caf3 100644 --- a/tests/cuid.net.tests/Cuid2Facts.cs +++ b/tests/cuid.net.tests/Cuid2Facts.cs @@ -13,7 +13,7 @@ public void Cuid2_Constructor() var cuidString = cuid.ToString(); var result = cuidString.Length == 24 - && cuidString.All(char.IsLetterOrDigit); + && cuidString.All(char.IsLetterOrDigit); Assert.True(result); } @@ -26,7 +26,7 @@ public void Cuid2_Constructor_DefinedLength() var cuidString = cuid.ToString(); var result = cuidString.Length == 10 - && cuidString.All(char.IsLetterOrDigit); + && cuidString.All(char.IsLetterOrDigit); Assert.True(result); } @@ -51,4 +51,4 @@ public void Cuid2_Equality() Assert.False(c1.GetHashCode() == c2.GetHashCode()); } -} \ No newline at end of file +} diff --git a/tests/cuid.net.tests/CuidFacts.cs b/tests/cuid.net.tests/CuidFacts.cs index 180a8b0..509f66d 100644 --- a/tests/cuid.net.tests/CuidFacts.cs +++ b/tests/cuid.net.tests/CuidFacts.cs @@ -6,7 +6,6 @@ namespace Visus.Cuid.Tests; using System.Text.Json; using System.Xml; using System.Xml.Serialization; -using Visus.Cuid; [ExcludeFromCodeCoverage] public class CuidFacts @@ -112,8 +111,8 @@ public void Cuid_NewCuid() var cuidString = cuid.ToString(); var result = cuidString.Length == 25 - && cuidString.All(char.IsLetterOrDigit) - && cuid != Cuid.Empty; + && cuidString.All(char.IsLetterOrDigit) + && cuid != Cuid.Empty; Assert.True(result); } @@ -214,7 +213,11 @@ public void Cuid_Xml_Serialize() var cuid = new Cuid(CuidString); var serializer = new XmlSerializer(typeof(Cuid)); - var settings = new XmlWriterSettings { Indent = false, Encoding = new UnicodeEncoding(false, false) }; + var settings = new XmlWriterSettings + { + Indent = false, + Encoding = new UnicodeEncoding(false, false) + }; using var stringWriter = new StringWriter(); using var xmlWriter = XmlWriter.Create(stringWriter, settings); @@ -223,4 +226,4 @@ public void Cuid_Xml_Serialize() Assert.Equal(expected, stringWriter.ToString()); } -} \ No newline at end of file +} diff --git a/tests/cuid.net.tests/Usings.cs b/tests/cuid.net.tests/Usings.cs index 8c927eb..c802f44 100644 --- a/tests/cuid.net.tests/Usings.cs +++ b/tests/cuid.net.tests/Usings.cs @@ -1 +1 @@ -global using Xunit; \ No newline at end of file +global using Xunit; diff --git a/tests/cuid.net.tests/cuid.net.tests.csproj b/tests/cuid.net.tests/cuid.net.tests.csproj index ffd7bbd..9a7f3da 100644 --- a/tests/cuid.net.tests/cuid.net.tests.csproj +++ b/tests/cuid.net.tests/cuid.net.tests.csproj @@ -11,13 +11,13 @@ - all - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -29,7 +29,7 @@ - +