diff --git a/.editorconfig b/.editorconfig index 08fcbcf..a8e429a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,31 +1,327 @@ +root = true +# All files [*] -charset = utf-8 -end_of_line = crlf -indent_size = 4 -indent_style = space insert_final_newline = true -max_line_length = 140 -tab_width = 4 +indent_style = space +indent_size = 4 trim_trailing_whitespace = true - -[*.cs] +charset = utf-8 +# Markdown files +[*.md] +max_line_length = 999999999 +# Xml project files +[*.csproj] +indent_size = 2 +ij_formatter_enabled = false +# Xml config files +[*.props] +indent_size = 2 +ij_formatter_enabled = false +# Xml files +[*.xml] +indent_size = 2 +# C# files +[{*.cs,*.cshtml}] +# Indentation and spacing +tab_width = 4 +max_line_length = 280 +# Organize usings +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = true +file_header_template = unset +# this. and Me. preferences +dotnet_style_qualification_for_event = false:silent +dotnet_style_qualification_for_field = false:silent +dotnet_style_qualification_for_method = false:silent +dotnet_style_qualification_for_property = false:silent +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true:silent +dotnet_style_predefined_type_for_member_access = true:silent +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent +# Modifier preferences +dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent +# Expression-level preferences +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_object_initializer = true:suggestion +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_return = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion +# Field preferences +dotnet_style_readonly_field = true:warning +# Parameter preferences +dotnet_code_quality_unused_parameters = all:suggestion +# Suppression preferences +dotnet_remove_unnecessary_suppression_exclusions = none +# var preferences +csharp_style_var_elsewhere = true:suggestion +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +# Expression-bodied members +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_lambdas = true:suggestion +csharp_style_expression_bodied_local_functions = false:silent +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent +# Pattern matching preferences +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_prefer_not_pattern = true:suggestion +csharp_style_prefer_pattern_matching = true:silent +csharp_style_prefer_switch_expression = true:suggestion +# Null-checking preferences +csharp_style_conditional_delegate_call = true:suggestion +# Modifier preferences +csharp_prefer_static_local_function = true:warning +csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async:suggestion +# Code-block preferences +csharp_prefer_braces = true:silent +csharp_prefer_simple_using_statement = true:suggestion +# Expression-level preferences +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion +csharp_style_pattern_local_over_anonymous_function = true:suggestion +csharp_style_prefer_index_operator = true:suggestion +csharp_style_prefer_range_operator = true:suggestion +csharp_style_throw_expression = true:suggestion +csharp_style_unused_value_assignment_preference = discard_variable:suggestion +csharp_style_unused_value_expression_statement_preference = discard_variable:silent +# 'using' directive preferences +csharp_using_directive_placement = outside_namespace:silent +#### C# Formatting Rules #### +# New line preferences +csharp_new_line_before_catch = true +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 +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true +# Space preferences +csharp_space_after_cast = true +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false +# Wrapping preferences +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true +# Naming rules +dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.symbols = types_and_namespaces +dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.style = pascalcase +dotnet_naming_rule.interfaces_should_be_ipascalcase.severity = suggestion +dotnet_naming_rule.interfaces_should_be_ipascalcase.symbols = interfaces +dotnet_naming_rule.interfaces_should_be_ipascalcase.style = ipascalcase +dotnet_naming_rule.type_parameters_should_be_tpascalcase.severity = suggestion +dotnet_naming_rule.type_parameters_should_be_tpascalcase.symbols = type_parameters +dotnet_naming_rule.type_parameters_should_be_tpascalcase.style = tpascalcase +dotnet_naming_rule.methods_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.methods_should_be_pascalcase.symbols = methods +dotnet_naming_rule.methods_should_be_pascalcase.style = pascalcase +dotnet_naming_rule.properties_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.properties_should_be_pascalcase.symbols = properties +dotnet_naming_rule.properties_should_be_pascalcase.style = pascalcase +dotnet_naming_rule.events_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.events_should_be_pascalcase.symbols = events +dotnet_naming_rule.events_should_be_pascalcase.style = pascalcase +dotnet_naming_rule.local_variables_should_be_camelcase.severity = suggestion +dotnet_naming_rule.local_variables_should_be_camelcase.symbols = local_variables +dotnet_naming_rule.local_variables_should_be_camelcase.style = camelcase +dotnet_naming_rule.local_constants_should_be_camelcase.severity = suggestion +dotnet_naming_rule.local_constants_should_be_camelcase.symbols = local_constants +dotnet_naming_rule.local_constants_should_be_camelcase.style = camelcase +dotnet_naming_rule.parameters_should_be_camelcase.severity = suggestion +dotnet_naming_rule.parameters_should_be_camelcase.symbols = parameters +dotnet_naming_rule.parameters_should_be_camelcase.style = camelcase +dotnet_naming_rule.public_fields_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.public_fields_should_be_pascalcase.symbols = public_fields +dotnet_naming_rule.public_fields_should_be_pascalcase.style = pascalcase +dotnet_naming_rule.private_fields_should_be__camelcase.severity = suggestion +dotnet_naming_rule.private_fields_should_be__camelcase.symbols = private_fields +dotnet_naming_rule.private_fields_should_be__camelcase.style = _camelcase +dotnet_naming_rule.private_static_fields_should_be_s_camelcase.severity = suggestion +dotnet_naming_rule.private_static_fields_should_be_s_camelcase.symbols = private_static_fields +dotnet_naming_rule.private_static_fields_should_be_s_camelcase.style = s_camelcase +dotnet_naming_rule.public_constant_fields_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.public_constant_fields_should_be_pascalcase.symbols = public_constant_fields +dotnet_naming_rule.public_constant_fields_should_be_pascalcase.style = pascalcase +dotnet_naming_rule.private_constant_fields_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.private_constant_fields_should_be_pascalcase.symbols = private_constant_fields +dotnet_naming_rule.private_constant_fields_should_be_pascalcase.style = pascalcase +dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.symbols = public_static_readonly_fields +dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.style = pascalcase +dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.symbols = private_static_readonly_fields +dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.style = pascalcase +dotnet_naming_rule.enums_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.enums_should_be_pascalcase.symbols = enums +dotnet_naming_rule.enums_should_be_pascalcase.style = pascalcase +dotnet_naming_rule.local_functions_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.local_functions_should_be_pascalcase.symbols = local_functions +dotnet_naming_rule.local_functions_should_be_pascalcase.style = pascalcase +dotnet_naming_rule.non_field_members_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascalcase.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascalcase.style = pascalcase +# Symbol specifications +dotnet_naming_symbols.interfaces.applicable_kinds = interface +dotnet_naming_symbols.interfaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.enums.applicable_kinds = enum +dotnet_naming_symbols.enums.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.events.applicable_kinds = event +dotnet_naming_symbols.events.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.methods.applicable_kinds = method +dotnet_naming_symbols.methods.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.properties.applicable_kinds = property +dotnet_naming_symbols.properties.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.public_fields.applicable_kinds = field +dotnet_naming_symbols.public_fields.applicable_accessibilities = public, internal +dotnet_naming_symbols.private_fields.applicable_kinds = field +dotnet_naming_symbols.private_fields.applicable_accessibilities = private, protected, protected_internal, private_protected +dotnet_naming_symbols.private_static_fields.applicable_kinds = field +dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private, protected, protected_internal, private_protected +dotnet_naming_symbols.private_static_fields.required_modifiers = static +dotnet_naming_symbols.types_and_namespaces.applicable_kinds = namespace, class, struct, interface, enum +dotnet_naming_symbols.types_and_namespaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.type_parameters.applicable_kinds = namespace +dotnet_naming_symbols.type_parameters.applicable_accessibilities = * +dotnet_naming_symbols.private_constant_fields.applicable_kinds = field +dotnet_naming_symbols.private_constant_fields.applicable_accessibilities = private, protected, protected_internal, private_protected +dotnet_naming_symbols.private_constant_fields.required_modifiers = const +dotnet_naming_symbols.local_variables.applicable_kinds = local +dotnet_naming_symbols.local_variables.applicable_accessibilities = local +dotnet_naming_symbols.local_constants.applicable_kinds = local +dotnet_naming_symbols.local_constants.applicable_accessibilities = local +dotnet_naming_symbols.local_constants.required_modifiers = const +dotnet_naming_symbols.parameters.applicable_kinds = parameter +dotnet_naming_symbols.parameters.applicable_accessibilities = * +dotnet_naming_symbols.public_constant_fields.applicable_kinds = field +dotnet_naming_symbols.public_constant_fields.applicable_accessibilities = public, internal +dotnet_naming_symbols.public_constant_fields.required_modifiers = const +dotnet_naming_symbols.public_static_readonly_fields.applicable_kinds = field +dotnet_naming_symbols.public_static_readonly_fields.applicable_accessibilities = public, internal +dotnet_naming_symbols.public_static_readonly_fields.required_modifiers = readonly, static +dotnet_naming_symbols.private_static_readonly_fields.applicable_kinds = field +dotnet_naming_symbols.private_static_readonly_fields.applicable_accessibilities = private, protected, protected_internal, private_protected +dotnet_naming_symbols.private_static_readonly_fields.required_modifiers = readonly, static +dotnet_naming_symbols.local_functions.applicable_kinds = local_function +dotnet_naming_symbols.local_functions.applicable_accessibilities = * +# Naming styles +dotnet_naming_style.pascalcase.capitalization = pascal_case +dotnet_naming_style.ipascalcase.required_prefix = I +dotnet_naming_style.ipascalcase.capitalization = pascal_case +dotnet_naming_style.tpascalcase.required_prefix = T +dotnet_naming_style.tpascalcase.capitalization = pascal_case +dotnet_naming_style._camelcase.required_prefix = _ +dotnet_naming_style._camelcase.capitalization = camel_case +dotnet_naming_style.camelcase.capitalization = camel_case +dotnet_naming_style.s_camelcase.required_prefix = s_ +dotnet_naming_style.s_camelcase.capitalization = camel_case +# Resharper / Rider +resharper_csharp_object_creation_when_type_evident = explicitly_typed +resharper_csharp_object_creation_when_type_not_evident = explicitly_typed +resharper_apply_auto_detected_rules = false +resharper_autodetect_indent_settings = false +resharper_braces_for_for = required +resharper_braces_for_foreach = required +resharper_braces_for_ifelse = required +resharper_braces_for_while = required +resharper_braces_redundant = false +csharp_indent_nested_usings_stmt = false +csharp_indent_nested_fixed_stmt = false +csharp_indent_nested_lock_stmt = false +csharp_indent_nested_for_stmt = true +csharp_indent_nested_foreach_stmt = true +csharp_indent_nested_while_stmt = true +csharp_wrap_after_declaration_lpar = true +csharp_wrap_parameters_style = chop_if_long +csharp_max_initializer_elements_on_line = 0 +csharp_max_array_initializer_elements_on_line = 0 +resharper_csharp_wrap_object_and_collection_initializer_style = chop_always csharp_braces_for_for = required csharp_braces_for_foreach = required csharp_braces_for_ifelse = required csharp_braces_for_while = required csharp_use_heuristics_for_body_style = false -csharp_keep_existing_attribute_arrangement = false csharp_place_attribute_on_same_line = never -csharp_wrap_after_declaration_lpar = true -csharp_wrap_parameters_style = chop_if_long csharp_wrap_before_comma = false # var preferences csharp_for_built_in_types = use_var_when_evident csharp_for_simple_types = use_var_when_evident csharp_for_other_types = use_var_when_evident - -[{*.yaml, *.yml}] -indent_size = 2 -trim_trailing_whitespace = true -insert_final_newline = false -max_line_length = off +# Arrangement of attributes +csharp_keep_existing_attribute_arrangement = false +csharp_place_type_attribute_on_same_line = false +csharp_place_method_attribute_on_same_line = false +csharp_place_accessorholder_attribute_on_same_line = false +csharp_place_accessor_attribute_on_same_line = false +csharp_place_field_attribute_on_same_line = false +# Diagnostics +# CA1054: URI parameters should not be strings +# A type declares a method with a string parameter whose name contains "uri", "Uri", "urn", "Urn", "url", or "Url", and the type does not declare a corresponding overload that takes a System.Uri parameter. +dotnet_diagnostic.CA1054.severity = suggestion +# CA1055: URI return values should not be strings +# The name of a method contains "uri", "Uri", "urn", "Urn", "url", or "Url", and the method returns a string. +dotnet_diagnostic.CA1055.severity = suggestion +# CA1056: URI properties should not be strings +# A type declares a string property whose name contains "uri", "Uri", "urn", "Urn", "url", or "Url". +dotnet_diagnostic.CA1056.severity = suggestion +# CA1200: Avoid using cref tags with a prefix +# The cref tag in an XML documentation comment uses a prefix. +dotnet_diagnostic.CA1200.severity = suggestion +# CA1716: Identifiers should not match keywords +# The name of a namespace, type, or virtual or interface member matches a reserved keyword in a programming language. +dotnet_diagnostic.CA1716.severity = suggestion +# CA1721: Property names should not match get methods +# The name of a member starts with 'Get' and otherwise matches the name of a property. For example, a type that contains a method that's named 'GetColor' and a property that's named 'Color' cause a rule violation +dotnet_diagnostic.CA1721.severity = none +# CA1819: Properties should not return arrays +# A property returns an array. +dotnet_diagnostic.CA1819.severity = suggestion +# CA2007: Do not directly await a Task +# An asynchronous method awaits a Task directly. +dotnet_diagnostic.CA2007.severity = none diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index a8b7688..d57d8c0 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -54,10 +54,10 @@ jobs: fi echo "version_with_suffix_dst=${version_with_suffix}" >> $GITHUB_ENV echo "has_suffix_dst=${has_suffix}" >> $GITHUB_ENV - - name: Setup .NET Core SDK 7.0.100 + - name: Setup .NET Core SDK 7.0.400 uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.100 + dotnet-version: 7.0.400 - name: Checkout source branch back uses: actions/checkout@v3 with: @@ -107,14 +107,14 @@ jobs: uses: actions/checkout@v3 with: ref: ${{ github.sha }} - - name: Setup .NET Core SDK 6.0.403 + - name: Setup .NET Core SDK 6.0.413 uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.403 - - name: Setup .NET Core SDK 7.0.100 + dotnet-version: 6.0.413 + - name: Setup .NET Core SDK 7.0.400 uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.100 + dotnet-version: 7.0.400 - name: Create coverage directory and promote absolute paths to env shell: bash run: | diff --git a/.github/workflows/push_to_main.yml b/.github/workflows/push_to_main.yml index 241dae3..362e799 100644 --- a/.github/workflows/push_to_main.yml +++ b/.github/workflows/push_to_main.yml @@ -44,14 +44,14 @@ jobs: uses: actions/checkout@v3 with: ref: ${{ github.sha }} - - name: Setup .NET Core SDK 6.0.403 + - name: Setup .NET Core SDK 6.0.413 uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.403 - - name: Setup .NET Core SDK 7.0.100 + dotnet-version: 6.0.413 + - name: Setup .NET Core SDK 7.0.400 uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.100 + dotnet-version: 7.0.400 - name: Create coverage directory and promote absolute paths to env shell: bash run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4395cce..9321440 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,14 +14,14 @@ jobs: uses: actions/checkout@v3 with: ref: ${{ github.sha }} - - name: Setup .NET Core SDK 6.0.403 + - name: Setup .NET Core SDK 6.0.413 uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.403 - - name: Setup .NET Core SDK 7.0.100 + dotnet-version: 6.0.413 + - name: Setup .NET Core SDK 7.0.400 uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.100 + dotnet-version: 7.0.400 - name: Create coverage directory and promote absolute paths to env shell: bash run: | diff --git a/README.md b/README.md index a1a1dda..6d400db 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # Dodo.Primitives -[![Latest release](https://img.shields.io/badge/nuget-2.0.0-blue?&kill_cache=1)](https://www.nuget.org/packages/Dodo.Primitives/2.0.0) -[![Coverage Status](https://coveralls.io/repos/github/dodopizza/primitives/badge.svg?branch=refs/tags/2.0.0&kill_cache=1)](https://coveralls.io/github/dodopizza/primitives?branch=refs/tags/2.0.0) +[![Latest release](https://img.shields.io/badge/nuget-2.0.1-blue?&kill_cache=1)](https://www.nuget.org/packages/Dodo.Primitives/2.0.1) +[![Coverage Status](https://coveralls.io/repos/github/dodopizza/primitives/badge.svg?branch=refs/tags/2.0.1&kill_cache=1)](https://coveralls.io/github/dodopizza/primitives?branch=refs/tags/2.0.1) Library provides .NET primitive types: -- [Uuid](./src/Dodo.Primitives/Uuid.cs) +- [Uuid](./src/Dodo.Primitives/Uuid.cs) and utils to work with types: -- [Hex](./src/Dodo.Primitives/Hex.cs) +- [Hex](./src/Dodo.Primitives/Hex.cs) ## Project goal @@ -19,22 +19,22 @@ The main goal is Uuid implementation according to the [RFC4122](https://tools.ie Our goal is to provide Uuid fully compliant with RFC4122 (big-endian layout) and preserve System.Guid-like behaviour. Also project contains generators to create different Uuid variants. Currently supported variants: -- Time-based (like [Uuid v1](https://tools.ietf.org/html/rfc4122#section-4.1.3)). +- Time-based (like [Uuid v1](https://tools.ietf.org/html/rfc4122#section-4.1.3)). - ```csharp - var uuid = Uuid.NewTimeBased(); - ``` + ```csharp + var uuid = Uuid.NewTimeBased(); + ``` -- Time-based, optimized for MySQL. +- Time-based, optimized for MySQL. - ```csharp - var uuid = Uuid.NewMySqlOptimized(); - ``` + ```csharp + var uuid = Uuid.NewMySqlOptimized(); + ``` - Equals `UUID_TO_BIN(UUID(), 1)` from [MySQL 8.0](https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_uuid-to-bin) + Equals `UUID_TO_BIN(UUID(), 1)` from [MySQL 8.0](https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_uuid-to-bin) ## Project documentation -- [Prerequisites, build and development](https://github.com/dodopizza/primitives/wiki/Prerequisites,-build-and-development) -- [Benchmarks](https://github.com/dodopizza/primitives/wiki/Benchmarks) +- [Prerequisites, build and development](https://github.com/dodopizza/primitives/wiki/Prerequisites,-build-and-development) +- [Benchmarks](https://github.com/dodopizza/primitives/wiki/Benchmarks) diff --git a/global.json b/global.json index 6545580..e944ed0 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { - "sdk": { - "version": "7.0.100", - "rollForward": "latestPatch" - } + "sdk": { + "version": "7.0.400", + "rollForward": "latestPatch" + } } diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 763b83d..8e6cff3 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,6 @@ - 2.0.0 + 2.0.1 diff --git a/src/Dodo.Primitives.Benchmarks/Benchmarks/CtorBenchmarks.cs b/src/Dodo.Primitives.Benchmarks/Benchmarks/CtorBenchmarks.cs index 8001180..d53a71a 100644 --- a/src/Dodo.Primitives.Benchmarks/Benchmarks/CtorBenchmarks.cs +++ b/src/Dodo.Primitives.Benchmarks/Benchmarks/CtorBenchmarks.cs @@ -14,7 +14,25 @@ public class CtorBenchmarks // byte[] [Benchmark] [BenchmarkCategory("byte[]")] - [Arguments(new byte[] { 253, 47, 238, 170, 214, 83, 143, 78, 140, 107, 139, 132, 94, 5, 145, 199 })] + [Arguments(new byte[] + { + 253, + 47, + 238, + 170, + 214, + 83, + 143, + 78, + 140, + 107, + 139, + 132, + 94, + 5, + 145, + 199 + })] public Guid guid_CtorByteArray(byte[] guidBytes) { return new Guid(guidBytes); @@ -22,7 +40,25 @@ public Guid guid_CtorByteArray(byte[] guidBytes) [Benchmark] [BenchmarkCategory("byte[]")] - [Arguments(new byte[] { 170, 238, 47, 253, 83, 214, 78, 143, 140, 107, 139, 132, 94, 5, 145, 199 })] + [Arguments(new byte[] + { + 170, + 238, + 47, + 253, + 83, + 214, + 78, + 143, + 140, + 107, + 139, + 132, + 94, + 5, + 145, + 199 + })] public Uuid uuid_CtorByteArray(byte[] uuidBytes) { return new Uuid(uuidBytes); @@ -31,7 +67,25 @@ public Uuid uuid_CtorByteArray(byte[] uuidBytes) // ReadOnlySpan [Benchmark(OperationsPerInvoke = 16)] [BenchmarkCategory("ReadOnlySpan")] - [Arguments(new byte[] { 253, 47, 238, 170, 214, 83, 143, 78, 140, 107, 139, 132, 94, 5, 145, 199 })] + [Arguments(new byte[] + { + 253, + 47, + 238, + 170, + 214, + 83, + 143, + 78, + 140, + 107, + 139, + 132, + 94, + 5, + 145, + 199 + })] [SuppressMessage("ReSharper", "ObjectCreationAsStatement")] public void guid_CtorReadOnlySpan(byte[] guidBytes) { @@ -59,7 +113,25 @@ public void guid_CtorReadOnlySpan(byte[] guidBytes) [Benchmark(OperationsPerInvoke = 16)] [BenchmarkCategory("ReadOnlySpan")] - [Arguments(new byte[] { 170, 238, 47, 253, 83, 214, 78, 143, 140, 107, 139, 132, 94, 5, 145, 199 })] + [Arguments(new byte[] + { + 170, + 238, + 47, + 253, + 83, + 214, + 78, + 143, + 140, + 107, + 139, + 132, + 94, + 5, + 145, + 199 + })] [SuppressMessage("ReSharper", "ObjectCreationAsStatement")] public void uuid_CtorReadOnlySpan(byte[] uuidBytes) { diff --git a/src/Dodo.Primitives.Benchmarks/Benchmarks/ImplementedInterfacesBenchmarks.cs b/src/Dodo.Primitives.Benchmarks/Benchmarks/ImplementedInterfacesBenchmarks.cs index 23f64ab..6271a76 100644 --- a/src/Dodo.Primitives.Benchmarks/Benchmarks/ImplementedInterfacesBenchmarks.cs +++ b/src/Dodo.Primitives.Benchmarks/Benchmarks/ImplementedInterfacesBenchmarks.cs @@ -46,22 +46,38 @@ public IEnumerable UuidArgs() public IEnumerable GuidSameValues() { - yield return new object[] { _guid, _guidSame }; + yield return new object[] + { + _guid, + _guidSame + }; } public IEnumerable UuidSameValues() { - yield return new object[] { _uuid, _uuidSame }; + yield return new object[] + { + _uuid, + _uuidSame + }; } public IEnumerable GuidDifferentValues() { - yield return new object[] { _guid, _guidDifferent }; + yield return new object[] + { + _guid, + _guidDifferent + }; } public IEnumerable UuidDifferentValues() { - yield return new object[] { _uuid, _uuidDifferent }; + yield return new object[] + { + _uuid, + _uuidDifferent + }; } // IEquatable.Equals with same value @@ -173,7 +189,7 @@ public int guid_CompareTo_T_DifferentValue(Guid guid, Guid differentValue) [SuppressMessage("ReSharper", "RedundantCast")] public int uuid_CompareToNull(Uuid uuid) { - return uuid.CompareTo((object)null); + return uuid.CompareTo((object) null); } [Benchmark] @@ -182,7 +198,6 @@ public int uuid_CompareToNull(Uuid uuid) [SuppressMessage("ReSharper", "RedundantCast")] public int guid_CompareToNull(Guid guid) { - return guid.CompareTo((object)null); + return guid.CompareTo((object) null); } -#nullable restore } diff --git a/src/Dodo.Primitives.Benchmarks/Benchmarks/OverridesBenchmarks.cs b/src/Dodo.Primitives.Benchmarks/Benchmarks/OverridesBenchmarks.cs index 985495f..3647ea5 100644 --- a/src/Dodo.Primitives.Benchmarks/Benchmarks/OverridesBenchmarks.cs +++ b/src/Dodo.Primitives.Benchmarks/Benchmarks/OverridesBenchmarks.cs @@ -41,22 +41,38 @@ public IEnumerable UuidArgs() public IEnumerable GuidSameValues() { - yield return new object[] { _guid, _guidSame }; + yield return new object[] + { + _guid, + _guidSame + }; } public IEnumerable UuidSameValues() { - yield return new object[] { _uuid, _uuidSame }; + yield return new object[] + { + _uuid, + _uuidSame + }; } public IEnumerable GuidDifferentTypesValues() { - yield return new[] { _guid, new object() }; + yield return new[] + { + _guid, + new object() + }; } public IEnumerable UuidDifferentTypesValues() { - yield return new[] { _uuid, new object() }; + yield return new[] + { + _uuid, + new object() + }; } // GetHashCode @@ -118,7 +134,7 @@ public bool guid_EqualsDifferentTypesValues(Guid guid, object differentTypeValue [MethodImpl(MethodImplOptions.NoInlining)] public bool uuid_EqualsWithNull(Uuid uuid) { - return uuid.Equals((object?)null); + return uuid.Equals((object?) null); } [Benchmark] @@ -128,6 +144,6 @@ public bool uuid_EqualsWithNull(Uuid uuid) [MethodImpl(MethodImplOptions.NoInlining)] public bool guid_EqualsWithNull(Guid guid) { - return guid.Equals((object?)null); + return guid.Equals((object?) null); } } diff --git a/src/Dodo.Primitives.Benchmarks/Benchmarks/TryParseBenchmarks.cs b/src/Dodo.Primitives.Benchmarks/Benchmarks/TryParseBenchmarks.cs index 9d7a35c..23799bd 100644 --- a/src/Dodo.Primitives.Benchmarks/Benchmarks/TryParseBenchmarks.cs +++ b/src/Dodo.Primitives.Benchmarks/Benchmarks/TryParseBenchmarks.cs @@ -419,7 +419,7 @@ private static string[] GenerateSometimesBrokenGuidsNStringsArray(int count) var random = new Random(); int* uuidIntegers = stackalloc int[4]; char* charToBreakPtr = stackalloc char[1]; - var charBytesPtr = (byte*)charToBreakPtr; + var charBytesPtr = (byte*) charToBreakPtr; var result = new string[count]; var breakUpperByteOnCharArray = new bool[32]; for (var i = 0; i < breakUpperByteOnCharArray.Length; i++) diff --git a/src/Dodo.Primitives.Benchmarks/Dodo.Primitives.Benchmarks.csproj b/src/Dodo.Primitives.Benchmarks/Dodo.Primitives.Benchmarks.csproj index 2ddcb5b..2efba26 100644 --- a/src/Dodo.Primitives.Benchmarks/Dodo.Primitives.Benchmarks.csproj +++ b/src/Dodo.Primitives.Benchmarks/Dodo.Primitives.Benchmarks.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj b/src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj index 48c064a..c9523f9 100644 --- a/src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj +++ b/src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj @@ -13,16 +13,16 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - - - + + + diff --git a/src/Dodo.Primitives.Tests/Hex/HexTestsData.cs b/src/Dodo.Primitives.Tests/Hex/HexTestsData.cs index f7af03f..f31bd4a 100644 --- a/src/Dodo.Primitives.Tests/Hex/HexTestsData.cs +++ b/src/Dodo.Primitives.Tests/Hex/HexTestsData.cs @@ -22,14 +22,30 @@ public static class HexTestsData public static readonly byte[][] ValidByteArrays = { - new byte[] { 13, 37, 42 }, - new byte[] { 42, 43, 43, 34, 35, 9, 12, 19, 93 }, - Enumerable.Repeat((byte)42, 17935).Select((b, index) => + new byte[] + { + 13, + 37, + 42 + }, + new byte[] + { + 42, + 43, + 43, + 34, + 35, + 9, + 12, + 19, + 93 + }, + Enumerable.Repeat((byte) 42, 17935).Select((b, index) => { byte result; unchecked { - result = (byte)(b + (byte)(index % byte.MaxValue)); + result = (byte) (b + (byte) (index % byte.MaxValue)); } return result; @@ -44,7 +60,7 @@ private static unsafe string[] GetBrokenHexStrings(string[] strings) var brokenString = new string(strings[i].ToCharArray()); fixed (char* brokenPtr = brokenString) { - var bytePtr = (byte*)brokenPtr; + var bytePtr = (byte*) brokenPtr; int problemType = i % 3; switch (problemType) { diff --git a/src/Dodo.Primitives.Tests/Uuids/Data/Rng.cs b/src/Dodo.Primitives.Tests/Uuids/Data/Rng.cs index 68681ec..c621995 100644 --- a/src/Dodo.Primitives.Tests/Uuids/Data/Rng.cs +++ b/src/Dodo.Primitives.Tests/Uuids/Data/Rng.cs @@ -20,15 +20,15 @@ public UuidRng(long seed) private int Next(int bits) // helper { - _seed = (_seed * A + C) & ((1L << 48) - 1); - return (int)(_seed >> (48 - bits)); + _seed = ((_seed * A) + C) & ((1L << 48) - 1); + return (int) (_seed >> (48 - bits)); } public unsafe int Next() { - double resultDouble = (((long)Next(26) << 27) + Next(27)) / (double)(1L << 53); + double resultDouble = (((long) Next(26) << 27) + Next(27)) / (double) (1L << 53); double* resultDoublePtr = &resultDouble; - var resultInt32Ptr = (int*)resultDoublePtr; + var resultInt32Ptr = (int*) resultDoublePtr; int hi = resultInt32Ptr[0]; int lo = resultInt32Ptr[1]; int result = hi ^ lo; diff --git a/src/Dodo.Primitives.Tests/Uuids/Data/Utf8JsonTestData.cs b/src/Dodo.Primitives.Tests/Uuids/Data/Utf8JsonTestData.cs index 22e6a48..be6d2ae 100644 --- a/src/Dodo.Primitives.Tests/Uuids/Data/Utf8JsonTestData.cs +++ b/src/Dodo.Primitives.Tests/Uuids/Data/Utf8JsonTestData.cs @@ -63,7 +63,7 @@ public static string ToUtf8EscapedString(Uuid uuid, string format) var escapedCharacters = new List(); foreach (char ch in uuidString) { - var intChar = (int)ch; + var intChar = (int) ch; escapedCharacters.Add("\\u" + intChar.ToString("x4")); } diff --git a/src/Dodo.Primitives.Tests/Uuids/Data/UuidTestData.cs b/src/Dodo.Primitives.Tests/Uuids/Data/UuidTestData.cs index 7e8ee65..1e6441e 100644 --- a/src/Dodo.Primitives.Tests/Uuids/Data/UuidTestData.cs +++ b/src/Dodo.Primitives.Tests/Uuids/Data/UuidTestData.cs @@ -10,215 +10,1592 @@ public static class UuidTestData { public static object[] CorrectUuidBytesArrays { get; } = { - new object[] { new byte[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160 } }, - new object[] { new byte[] { 163, 167, 252, 114, 206, 122, 17, 233, 128, 237, 0, 13, 58, 17, 37, 233 } }, - new object[] { new byte[] { 241, 186, 230, 119, 206, 55, 78, 240, 175, 188, 141, 114, 36, 63, 217, 193 } }, - new object[] { new byte[] { 230, 35, 75, 5, 129, 19, 99, 68, 152, 188, 145, 109, 120, 166, 14, 235 } }, - new object[] { new byte[] { 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, - new object[] { new byte[] { 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0 } }, - new object[] { new byte[] { 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0 } }, - new object[] { new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0 } }, - new object[] { new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255 } } + new object[] + { + new byte[] + { + 10, + 20, + 30, + 40, + 50, + 60, + 70, + 80, + 90, + 100, + 110, + 120, + 130, + 140, + 150, + 160 + } + }, + new object[] + { + new byte[] + { + 163, + 167, + 252, + 114, + 206, + 122, + 17, + 233, + 128, + 237, + 0, + 13, + 58, + 17, + 37, + 233 + } + }, + new object[] + { + new byte[] + { + 241, + 186, + 230, + 119, + 206, + 55, + 78, + 240, + 175, + 188, + 141, + 114, + 36, + 63, + 217, + 193 + } + }, + new object[] + { + new byte[] + { + 230, + 35, + 75, + 5, + 129, + 19, + 99, + 68, + 152, + 188, + 145, + 109, + 120, + 166, + 14, + 235 + } + }, + new object[] + { + new byte[] + { + 255, + 255, + 255, + 255, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + } + }, + new object[] + { + new byte[] + { + 0, + 0, + 0, + 0, + 255, + 255, + 255, + 255, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + } + }, + new object[] + { + new byte[] + { + 0, + 0, + 0, + 0, + 255, + 255, + 255, + 255, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + } + }, + new object[] + { + new byte[] + { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 255, + 255, + 255, + 255, + 0, + 0, + 0, + 0 + } + }, + new object[] + { + new byte[] + { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 255, + 255, + 255, + 255 + } + } }; public static object[] CorrectCompareToArraysAndResult { get; } = { new object[] { - new byte[] { 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 17, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 17, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 17, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 17, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 29, 17, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 29, 17, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 29, 17, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 29, 17, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 173, 29, 17, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 173, 29, 17, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 173, 29, 17, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 173, 29, 17, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 234, 173, 29, 17, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 234, 173, 29, 17, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 234, 173, 29, 17, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 234, 173, 29, 17, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 97, 234, 173, 29, 17, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 97, 234, 173, 29, 17, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 97, 234, 173, 29, 17, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 97, 234, 173, 29, 17, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 23, 97, 234, 173, 29, 17, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 23, 97, 234, 173, 29, 17, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 23, 97, 234, 173, 29, 17, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 23, 97, 234, 173, 29, 17, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 81, 23, 97, 234, 173, 29, 17, 42, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 81, 23, 97, 234, 173, 29, 17, 13, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 81, 23, 97, 234, 173, 29, 17, 13, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 81, 23, 97, 234, 173, 29, 17, 42, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 125, 81, 23, 97, 234, 173, 29, 17, 42, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 125, 81, 23, 97, 234, 173, 29, 17, 13, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 125, 81, 23, 97, 234, 173, 29, 17, 13, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 125, 81, 23, 97, 234, 173, 29, 17, 42, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 69, 125, 81, 23, 97, 234, 173, 29, 17, 42, 0, 0, 0, 0, 0, 0 }, - new byte[] { 69, 125, 81, 23, 97, 234, 173, 29, 17, 13, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 69, 125, 81, 23, 97, 234, 173, 29, 17, 13, 0, 0, 0, 0, 0, 0 }, - new byte[] { 69, 125, 81, 23, 97, 234, 173, 29, 17, 42, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 42, 0, 0, 0, 0, 0 }, - new byte[] { 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 13, 0, 0, 0, 0, 0 }, + new byte[] + { + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 13, 0, 0, 0, 0, 0 }, - new byte[] { 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 42, 0, 0, 0, 0, 0 }, + new byte[] + { + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 42, 0, 0, 0, 0 }, - new byte[] { 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 13, 0, 0, 0, 0 }, + new byte[] + { + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 13, 0, 0, 0, 0 }, - new byte[] { 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 42, 0, 0, 0, 0 }, + new byte[] + { + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 42, 0, 0, 0 }, - new byte[] { 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 13, 0, 0, 0 }, + new byte[] + { + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0 + }, + new byte[] + { + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 13, 0, 0, 0 }, - new byte[] { 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 42, 0, 0, 0 }, + new byte[] + { + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0, + 0 + }, + new byte[] + { + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 42, 0, 0 }, - new byte[] { 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 13, 0, 0 }, + new byte[] + { + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0 + }, + new byte[] + { + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0 + }, 1 }, new object[] { - new byte[] { 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 13, 0, 0 }, - new byte[] { 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 42, 0, 0 }, + new byte[] + { + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0, + 0 + }, + new byte[] + { + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0, + 0 + }, -1 }, new object[] { - new byte[] { 99, 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 42, 0 }, - new byte[] { 99, 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 13, 0 }, + new byte[] + { + 99, + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0 + }, + new byte[] + { + 99, + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0 + }, 1 }, new object[] { - new byte[] { 99, 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 13, 0 }, - new byte[] { 99, 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 42, 0 }, + new byte[] + { + 99, + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13, + 0 + }, + new byte[] + { + 99, + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42, + 0 + }, -1 }, new object[] { - new byte[] { 72, 99, 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 42 }, - new byte[] { 72, 99, 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 13 }, + new byte[] + { + 72, + 99, + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42 + }, + new byte[] + { + 72, + 99, + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13 + }, 1 }, new object[] { - new byte[] { 72, 99, 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 13 }, - new byte[] { 72, 99, 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17, 42 }, + new byte[] + { + 72, + 99, + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 13 + }, + new byte[] + { + 72, + 99, + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17, + 42 + }, -1 }, new object[] { - new byte[] { 1, 72, 99, 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17 }, - new byte[] { 1, 72, 99, 252, 201, 77, 117, 69, 125, 81, 23, 97, 234, 173, 29, 17 }, + new byte[] + { + 1, + 72, + 99, + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17 + }, + new byte[] + { + 1, + 72, + 99, + 252, + 201, + 77, + 117, + 69, + 125, + 81, + 23, + 97, + 234, + 173, + 29, + 17 + }, 0 } }; @@ -227,26 +1604,170 @@ public static class UuidTestData { new object[] { - new byte[] { 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, false }, new object[] { - new byte[] { 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, true }, new object[] { - new byte[] { 13, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 13, 0, 0, 0, 0, 0, 0, 0, 37, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 37, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, false }, new object[] { - new byte[] { 13, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 13, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0 }, + new byte[] + { + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, + new byte[] + { + 13, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 42, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }, true } }; @@ -332,10 +1853,10 @@ public static object[] LeftLessThanRight() var results = new List(); foreach (object arg in src) { - var args = (object[])arg; - var left = (byte[])args[0]; - var right = (byte[])args[1]; - var flag = (int)args[2]; + var args = (object[]) arg; + var left = (byte[]) args[0]; + var right = (byte[]) args[1]; + var flag = (int) args[2]; if (flag == -1) { var outputArgs = new object[] @@ -356,10 +1877,10 @@ public static object[] RightLessThanLeft() var results = new List(); foreach (object arg in src) { - var args = (object[])arg; - var left = (byte[])args[0]; - var right = (byte[])args[1]; - var flag = (int)args[2]; + var args = (object[]) arg; + var left = (byte[]) args[0]; + var right = (byte[]) args[1]; + var flag = (int) args[2]; if (flag == 1) { var outputArgs = new object[] diff --git a/src/Dodo.Primitives.Tests/Uuids/Data/UuidTestsUtils.cs b/src/Dodo.Primitives.Tests/Uuids/Data/UuidTestsUtils.cs index e9fb2ba..270aaac 100644 --- a/src/Dodo.Primitives.Tests/Uuids/Data/UuidTestsUtils.cs +++ b/src/Dodo.Primitives.Tests/Uuids/Data/UuidTestsUtils.cs @@ -261,49 +261,53 @@ public static UuidStringWithBytes[] GenerateNStrings() { var resultStrings = new List(); for (int stringsToCreate = 32, itemsToFill = 1; stringsToCreate > 0; stringsToCreate >>= 1, itemsToFill <<= 1) - for (var stringIndex = 0; stringIndex < stringsToCreate; stringIndex++) { - resultStrings.Add( - string.Create( - 32, - (stringIndex * itemsToFill, itmesToFill: itemsToFill), - (result, state) => - { - (int startPositionToFill, int itemsToFillCount) = state; - for (var j = 0; j < 32; j++) - { - result[j] = '0'; - } - - result[startPositionToFill] = '1'; - for (var j = 0; j < itemsToFillCount; j++) + for (var stringIndex = 0; stringIndex < stringsToCreate; stringIndex++) + { + resultStrings.Add( + string.Create( + 32, + (stringIndex * itemsToFill, itmesToFill: itemsToFill), + (result, state) => { - result[startPositionToFill + j] = '1'; - } - })); + (int startPositionToFill, int itemsToFillCount) = state; + for (var j = 0; j < 32; j++) + { + result[j] = '0'; + } + + result[startPositionToFill] = '1'; + for (var j = 0; j < itemsToFillCount; j++) + { + result[startPositionToFill + j] = '1'; + } + })); + } } for (int stringsToCreate = 32, itemsToFill = 1; stringsToCreate > 0; stringsToCreate >>= 1, itemsToFill <<= 1) - for (var stringIndex = 0; stringIndex < stringsToCreate; stringIndex++) { - resultStrings.Add( - string.Create( - 32, - (stringIndex * itemsToFill, itmesToFill: itemsToFill), - (result, state) => - { - (int startPositionToFill, int itemsToFillCount) = state; - for (var j = 0; j < 32; j++) - { - result[j] = '1'; - } - - result[startPositionToFill] = '1'; - for (var j = 0; j < itemsToFillCount; j++) + for (var stringIndex = 0; stringIndex < stringsToCreate; stringIndex++) + { + resultStrings.Add( + string.Create( + 32, + (stringIndex * itemsToFill, itmesToFill: itemsToFill), + (result, state) => { - result[startPositionToFill + j] = '0'; - } - })); + (int startPositionToFill, int itemsToFillCount) = state; + for (var j = 0; j < 32; j++) + { + result[j] = '1'; + } + + result[startPositionToFill] = '1'; + for (var j = 0; j < itemsToFillCount; j++) + { + result[startPositionToFill + j] = '0'; + } + })); + } } string[] nStrings = resultStrings.Distinct().ToArray(); @@ -390,7 +394,7 @@ private static unsafe string[] GenerateBrokenStringsArray( var rng = new UuidRng(1337); int* uuidIntegers = stackalloc int[4]; char* charToBreakPtr = stackalloc char[1]; - var charBytesPtr = (byte*)charToBreakPtr; + var charBytesPtr = (byte*) charToBreakPtr; var result = new string[count]; var breakUpperByteOnCharArray = new bool[outputFormatSize]; for (var i = 0; i < breakUpperByteOnCharArray.Length; i++) diff --git a/src/Dodo.Primitives.Tests/Uuids/SystemTextJsonUuidJsonConverterDictionaryPropertyTests.cs b/src/Dodo.Primitives.Tests/Uuids/SystemTextJsonUuidJsonConverterDictionaryPropertyTests.cs new file mode 100644 index 0000000..535d320 --- /dev/null +++ b/src/Dodo.Primitives.Tests/Uuids/SystemTextJsonUuidJsonConverterDictionaryPropertyTests.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using System.IO; +using System.Text.Json; +using System.Threading.Tasks; +using NUnit.Framework; + +namespace Dodo.Primitives.Tests.Uuids; + +public class SystemTextJsonUuidJsonConverterDictionaryPropertyTests +{ + [Test] + public async Task ReadCorrectDictionaryPropertyUuid() + { + var expectedUuid = new Uuid("d0bec403-3323-44df-9dd4-4456121ab00b"); + + var options = new JsonSerializerOptions(); + options.Converters.Add(new SystemTextJsonUuidJsonConverter()); + + await using Stream stream = GenerateStreamFromString("""{"d0bec403332344df9dd44456121ab00b": 1}"""); + + var result = await JsonSerializer.DeserializeAsync>( + stream, + options + ); + Assert.NotNull(result); + if (result != null) + { + Assert.IsTrue(result.ContainsKey(expectedUuid)); + Assert.AreEqual(1, result[expectedUuid]); + } + } + + [Test] + public void WriteCorrectDictionaryPropertyUuid() + { + var expectedValue = """{"d0bec403332344df9dd44456121ab00b":1}"""; + + var target = new Dictionary + { + { new Uuid("d0bec403332344df9dd44456121ab00b"), 1 } + }; + + var options = new JsonSerializerOptions(); + options.Converters.Add(new SystemTextJsonUuidJsonConverter()); + + string actualValue = JsonSerializer.Serialize(target, options); + + Assert.AreEqual(expectedValue, actualValue); + } + + public static Stream GenerateStreamFromString(string s) + { + var stream = new MemoryStream(); + var writer = new StreamWriter(stream); + writer.Write(s); + writer.Flush(); + stream.Position = 0; + return stream; + } +} diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidCompareToTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidCompareToTests.cs index 56f8259..86aa8c5 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidCompareToTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidCompareToTests.cs @@ -13,7 +13,7 @@ public void CompareToObjectCorrect( int expectedResult) { var uuid = new Uuid(correctBytes); - var uuidToCompareAsObject = (object)new Uuid(correctCompareToBytes); + var uuidToCompareAsObject = (object) new Uuid(correctCompareToBytes); int compareResult = uuid.CompareTo(uuidToCompareAsObject); diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidCtorTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidCtorTests.cs index 57fd988..370d81d 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidCtorTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidCtorTests.cs @@ -17,7 +17,7 @@ public unsafe void CtorFromByteArrayCorrectBytes(byte[] correctBytes) var uuidBytes = new byte[16]; fixed (byte* pinnedUuidArray = uuidBytes) { - *(Uuid*)pinnedUuidArray = uuid; + *(Uuid*) pinnedUuidArray = uuid; } Assert.AreEqual(correctBytes, uuidBytes); @@ -29,7 +29,7 @@ public void CtorFromByteArrayNullShouldThrows() #nullable disable Assert.Throws(() => { - var _ = new Uuid((byte[])null); + var _ = new Uuid((byte[]) null); }); #nullable restore } @@ -39,7 +39,12 @@ public void CtorFromByteArrayNot16BytesShouldThrows() { Assert.Throws(() => { - var _ = new Uuid(new byte[] { 1, 2, 3 }); + var _ = new Uuid(new byte[] + { + 1, + 2, + 3 + }); }); } @@ -57,7 +62,7 @@ public unsafe void CtorFromPtrCorrectData(byte[] correctBytes) var uuidBytes = new byte[16]; fixed (byte* pinnedUuidArray = uuidBytes) { - *(Uuid*)pinnedUuidArray = uuid; + *(Uuid*) pinnedUuidArray = uuid; } Assert.AreEqual(correctBytes, uuidBytes); @@ -72,7 +77,7 @@ public unsafe void CtorFromReadOnlySpanCorrectBytes(byte[] correctBytes) var uuidBytes = new byte[16]; fixed (byte* pinnedUuidArray = uuidBytes) { - *(Uuid*)pinnedUuidArray = uuid; + *(Uuid*) pinnedUuidArray = uuid; } Assert.AreEqual(correctBytes, uuidBytes); @@ -83,7 +88,12 @@ public void CtorFromReadOnlySpanNot16BytesShouldThrows() { Assert.Throws(() => { - var span = new ReadOnlySpan(new byte[] { 1, 2, 3 }); + var span = new ReadOnlySpan(new byte[] + { + 1, + 2, + 3 + }); var _ = new Uuid(span); }); } @@ -99,7 +109,7 @@ public void CtorFromStringNullShouldThrows() { #nullable disable // ReSharper disable once RedundantCast - var _ = new Uuid((string)null); + var _ = new Uuid((string) null); #nullable restore }); } @@ -138,7 +148,7 @@ public unsafe void CtorFromStringCorrectNString() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -161,7 +171,7 @@ public unsafe void CtorFromCharSpanCorrectN() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -188,7 +198,7 @@ public unsafe void CtorFromStringCorrectDString() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -211,7 +221,7 @@ public unsafe void CtorFromCharSpanCorrectD() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -238,7 +248,7 @@ public unsafe void CtorFromStringCorrectBString() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -261,7 +271,7 @@ public unsafe void CtorFromCharSpanCorrectB() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -288,7 +298,7 @@ public unsafe void CtorFromStringCorrectPString() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -311,7 +321,7 @@ public unsafe void CtorFromCharSpanCorrectP() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -338,7 +348,7 @@ public unsafe void CtorFromStringCorrectXString() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -361,7 +371,7 @@ public unsafe void CtorFromCharSpanCorrectX() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidEqualsTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidEqualsTests.cs index 6fe465d..36c0321 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidEqualsTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidEqualsTests.cs @@ -19,7 +19,7 @@ public void EqualsWithObjectNullReturnFalse(byte[] correctBytes) public void EqualsWithObjectOtherTypeReturnFalse(byte[] correctBytes) { var uuid = new Uuid(correctBytes); - var objectWithAnotherType = (object)42; + var objectWithAnotherType = (object) 42; bool isEquals = uuid.Equals(objectWithAnotherType); @@ -33,7 +33,7 @@ public void EqualsWithObjectUuid( bool expectedResult) { var uuid = new Uuid(correctBytes); - var objectUuid = (object)new Uuid(correctEqualsBytes); + var objectUuid = (object) new Uuid(correctEqualsBytes); bool isEquals = uuid.Equals(objectUuid); diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidGeneratorTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidGeneratorTests.cs index 65b6b10..8394b4a 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidGeneratorTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidGeneratorTests.cs @@ -19,13 +19,13 @@ public unsafe void NewTimeBased() DateTimeOffset startDate = DateTimeOffset.UtcNow; var uuid = Uuid.NewTimeBased(); DateTimeOffset endDate = DateTimeOffset.UtcNow; - var uuidPtr = (byte*)&uuid; + var uuidPtr = (byte*) &uuid; long ticks = (endDate - startDate).Ticks + 1; for (var i = 0; i < ticks; i++) { long attemptTicks = startDate.Ticks + i - ChristianCalendarGregorianReformTicksDate; - var ticksPtr = (byte*)&attemptTicks; + var ticksPtr = (byte*) &attemptTicks; if (IsTimeBasedUuidForSpecifiedTime(ticksPtr, uuidPtr)) { Assert.Pass(); @@ -41,13 +41,13 @@ public unsafe void NewMySqlOptimized() DateTimeOffset startDate = DateTimeOffset.UtcNow; var uuid = Uuid.NewMySqlOptimized(); DateTimeOffset endDate = DateTimeOffset.UtcNow; - var uuidPtr = (byte*)&uuid; + var uuidPtr = (byte*) &uuid; long ticks = (endDate - startDate).Ticks + 1; for (var i = 0; i < ticks; i++) { long attemptTicks = startDate.Ticks + i - ChristianCalendarGregorianReformTicksDate; - var ticksPtr = (byte*)&attemptTicks; + var ticksPtr = (byte*) &attemptTicks; if (IsMySqlOptimizedUuidForSpecifiedTime(ticksPtr, uuidPtr)) { Assert.Pass(); @@ -65,14 +65,14 @@ private unsafe bool IsTimeBasedUuidForSpecifiedTime(byte* ticksPtr, byte* uuidBy && uuidBytes[3] == ticksPtr[0] && uuidBytes[4] == ticksPtr[5] && uuidBytes[5] == ticksPtr[4] - && uuidBytes[6] == (byte)((ticksPtr[7] & ResetVersionMask) | Version1Flag) + && uuidBytes[6] == (byte) ((ticksPtr[7] & ResetVersionMask) | Version1Flag) && uuidBytes[7] == ticksPtr[6] - && uuidBytes[8] == (byte)((uuidBytes[8] & ResetReservedMask) | ReservedFlag); + && uuidBytes[8] == (byte) ((uuidBytes[8] & ResetReservedMask) | ReservedFlag); } private unsafe bool IsMySqlOptimizedUuidForSpecifiedTime(byte* ticksPtr, byte* uuidBytes) { - return uuidBytes[0] == (byte)((ticksPtr[7] & ResetVersionMask) | Version1Flag) + return uuidBytes[0] == (byte) ((ticksPtr[7] & ResetVersionMask) | Version1Flag) && uuidBytes[1] == ticksPtr[6] && uuidBytes[2] == ticksPtr[5] && uuidBytes[3] == ticksPtr[4] @@ -80,6 +80,6 @@ private unsafe bool IsMySqlOptimizedUuidForSpecifiedTime(byte* ticksPtr, byte* u && uuidBytes[5] == ticksPtr[2] && uuidBytes[6] == ticksPtr[1] && uuidBytes[7] == ticksPtr[0] - && uuidBytes[8] == (byte)((uuidBytes[8] & ResetReservedMask) | ReservedFlag); + && uuidBytes[8] == (byte) ((uuidBytes[8] & ResetReservedMask) | ReservedFlag); } } diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidGetHashCodeTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidGetHashCodeTests.cs index 2929658..e9b7747 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidGetHashCodeTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidGetHashCodeTests.cs @@ -11,7 +11,7 @@ public unsafe void GetHashCode(byte[] correctBytes) var uuid = new Uuid(correctBytes); Uuid* uuidPtr = stackalloc Uuid[1]; uuidPtr[0] = uuid; - var intPtr = (int*)uuidPtr; + var intPtr = (int*) uuidPtr; int int0 = intPtr[0]; int int1 = intPtr[1]; int int2 = intPtr[2]; diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidParseExactTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidParseExactTests.cs index d3a350e..ea5fc1f 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidParseExactTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidParseExactTests.cs @@ -148,8 +148,8 @@ public unsafe void ParseExactCorrectNCorrectFormat() var actualBytesSpan = new byte[16]; fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) { - *(Uuid*)pinnedString = parsedUuidString; - *(Uuid*)pinnedSpan = parsedUuidSpan; + *(Uuid*) pinnedString = parsedUuidString; + *(Uuid*) pinnedSpan = parsedUuidSpan; } results.Add(actualBytesString); @@ -170,19 +170,21 @@ public void ParseExactCorrectNIncorrectFormat() Assert.Multiple(() => { foreach (UuidStringWithBytes correctNString in UuidTestData.CorrectNStrings) - foreach (string format in UuidTestData.Formats.AllExceptN) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.AllExceptN) { - Uuid _ = Uuid.ParseExact(correctNString.String, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(correctNString.String, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(correctNString.String.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(correctNString.String.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -193,19 +195,21 @@ public void ParseExactIncorrectNCorrectFormat() Assert.Multiple(() => { foreach (string brokenNString in UuidTestData.BrokenNStrings) - foreach (string format in UuidTestData.Formats.N) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.N) { - Uuid _ = Uuid.ParseExact(brokenNString, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(brokenNString, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(brokenNString.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(brokenNString.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -216,19 +220,21 @@ public void ParseExactNotNStringCorrectFormat() Assert.Multiple(() => { foreach (UuidStringWithBytes correctDString in UuidTestData.CorrectDStrings) - foreach (string format in UuidTestData.Formats.N) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.N) { - Uuid _ = Uuid.ParseExact(correctDString.String, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(correctDString.String, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(correctDString.String.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(correctDString.String.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -256,8 +262,8 @@ public unsafe void ParseExactCorrectDCorrectFormat() var actualBytesSpan = new byte[16]; fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) { - *(Uuid*)pinnedString = parsedUuidString; - *(Uuid*)pinnedSpan = parsedUuidSpan; + *(Uuid*) pinnedString = parsedUuidString; + *(Uuid*) pinnedSpan = parsedUuidSpan; } results.Add(actualBytesString); @@ -278,19 +284,21 @@ public void ParseExactCorrectDIncorrectFormat() Assert.Multiple(() => { foreach (UuidStringWithBytes correctDString in UuidTestData.CorrectDStrings) - foreach (string format in UuidTestData.Formats.AllExceptD) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.AllExceptD) { - Uuid _ = Uuid.ParseExact(correctDString.String, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(correctDString.String, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(correctDString.String.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(correctDString.String.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -301,19 +309,21 @@ public void ParseExactIncorrectDCorrectFormat() Assert.Multiple(() => { foreach (string brokenDString in UuidTestData.BrokenDStrings) - foreach (string format in UuidTestData.Formats.D) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.D) { - Uuid _ = Uuid.ParseExact(brokenDString, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(brokenDString, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(brokenDString.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(brokenDString.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -324,19 +334,21 @@ public void ParseExactNotDStringCorrectFormat() Assert.Multiple(() => { foreach (UuidStringWithBytes correctNString in UuidTestData.CorrectNStrings) - foreach (string format in UuidTestData.Formats.D) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.D) { - Uuid _ = Uuid.ParseExact(correctNString.String, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(correctNString.String, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(correctNString.String.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(correctNString.String.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -364,8 +376,8 @@ public unsafe void ParseExactCorrectBCorrectFormat() var actualBytesSpan = new byte[16]; fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) { - *(Uuid*)pinnedString = parsedUuidString; - *(Uuid*)pinnedSpan = parsedUuidSpan; + *(Uuid*) pinnedString = parsedUuidString; + *(Uuid*) pinnedSpan = parsedUuidSpan; } results.Add(actualBytesString); @@ -386,19 +398,21 @@ public void ParseExactCorrectBIncorrectFormat() Assert.Multiple(() => { foreach (UuidStringWithBytes correctBString in UuidTestData.CorrectBStrings) - foreach (string format in UuidTestData.Formats.AllExceptB) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.AllExceptB) { - Uuid _ = Uuid.ParseExact(correctBString.String, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(correctBString.String, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(correctBString.String.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(correctBString.String.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -409,19 +423,21 @@ public void ParseExactIncorrectBCorrectFormat() Assert.Multiple(() => { foreach (string brokenBString in UuidTestData.BrokenBStrings) - foreach (string format in UuidTestData.Formats.B) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.B) { - Uuid _ = Uuid.ParseExact(brokenBString, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(brokenBString, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(brokenBString.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(brokenBString.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -432,19 +448,21 @@ public void ParseExactNotBStringCorrectFormat() Assert.Multiple(() => { foreach (UuidStringWithBytes correctNString in UuidTestData.CorrectNStrings) - foreach (string format in UuidTestData.Formats.B) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.B) { - Uuid _ = Uuid.ParseExact(correctNString.String, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(correctNString.String, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(correctNString.String.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(correctNString.String.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -472,8 +490,8 @@ public unsafe void ParseExactCorrectPCorrectFormat() var actualBytesSpan = new byte[16]; fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) { - *(Uuid*)pinnedString = parsedUuidString; - *(Uuid*)pinnedSpan = parsedUuidSpan; + *(Uuid*) pinnedString = parsedUuidString; + *(Uuid*) pinnedSpan = parsedUuidSpan; } results.Add(actualBytesString); @@ -494,19 +512,21 @@ public void ParseExactCorrectPIncorrectFormat() Assert.Multiple(() => { foreach (UuidStringWithBytes correctPString in UuidTestData.CorrectPStrings) - foreach (string format in UuidTestData.Formats.AllExceptP) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.AllExceptP) { - Uuid _ = Uuid.ParseExact(correctPString.String, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(correctPString.String, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(correctPString.String.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(correctPString.String.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -517,19 +537,21 @@ public void ParseExactIncorrectPCorrectFormat() Assert.Multiple(() => { foreach (string brokenPString in UuidTestData.BrokenPStrings) - foreach (string format in UuidTestData.Formats.P) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.P) { - Uuid _ = Uuid.ParseExact(brokenPString, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(brokenPString, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(brokenPString.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(brokenPString.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -540,19 +562,21 @@ public void ParseExactNotPStringCorrectFormat() Assert.Multiple(() => { foreach (UuidStringWithBytes correctNString in UuidTestData.CorrectNStrings) - foreach (string format in UuidTestData.Formats.P) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.P) { - Uuid _ = Uuid.ParseExact(correctNString.String, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(correctNString.String, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(correctNString.String.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(correctNString.String.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -580,8 +604,8 @@ public unsafe void ParseExactCorrectXCorrectFormat() var actualBytesSpan = new byte[16]; fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) { - *(Uuid*)pinnedString = parsedUuidString; - *(Uuid*)pinnedSpan = parsedUuidSpan; + *(Uuid*) pinnedString = parsedUuidString; + *(Uuid*) pinnedSpan = parsedUuidSpan; } results.Add(actualBytesString); @@ -602,19 +626,21 @@ public void ParseExactCorrectXIncorrectFormat() Assert.Multiple(() => { foreach (UuidStringWithBytes correctXString in UuidTestData.CorrectXStrings) - foreach (string format in UuidTestData.Formats.AllExceptX) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.AllExceptX) { - Uuid _ = Uuid.ParseExact(correctXString.String, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(correctXString.String, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(correctXString.String.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(correctXString.String.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -625,19 +651,21 @@ public void ParseExactIncorrectXCorrectFormat() Assert.Multiple(() => { foreach (string brokenXString in UuidTestData.BrokenXStrings) - foreach (string format in UuidTestData.Formats.X) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.X) { - Uuid _ = Uuid.ParseExact(brokenXString, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(brokenXString, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(brokenXString.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(brokenXString.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } @@ -648,19 +676,21 @@ public void ParseExactNotXStringCorrectFormat() Assert.Multiple(() => { foreach (UuidStringWithBytes correctNString in UuidTestData.CorrectNStrings) - foreach (string format in UuidTestData.Formats.X) { - Assert.Throws(() => + foreach (string format in UuidTestData.Formats.X) { - Uuid _ = Uuid.ParseExact(correctNString.String, format); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact(correctNString.String, format); + }); - Assert.Throws(() => - { - Uuid _ = Uuid.ParseExact( - new ReadOnlySpan(correctNString.String.ToCharArray()), - new ReadOnlySpan(format.ToCharArray())); - }); + Assert.Throws(() => + { + Uuid _ = Uuid.ParseExact( + new ReadOnlySpan(correctNString.String.ToCharArray()), + new ReadOnlySpan(format.ToCharArray())); + }); + } } }); } diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidParseTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidParseTests.cs index 4cbb6f6..70bcd13 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidParseTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidParseTests.cs @@ -55,7 +55,7 @@ public unsafe void ParseCorrectNString() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -78,7 +78,7 @@ public unsafe void ParseCorrectNSpan() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -198,7 +198,7 @@ public unsafe void ParseCorrectDString() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -221,7 +221,7 @@ public unsafe void ParseCorrectDSpan() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -341,7 +341,7 @@ public unsafe void ParseCorrectBString() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -364,7 +364,7 @@ public unsafe void ParseCorrectBSpan() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -484,7 +484,7 @@ public unsafe void ParseCorrectPString() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -507,7 +507,7 @@ public unsafe void ParseCorrectPSpan() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -627,7 +627,7 @@ public unsafe void ParseCorrectXString() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -650,7 +650,7 @@ public unsafe void ParseCorrectXSpan() var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidParseWithFormatProviderTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidParseWithFormatProviderTests.cs index d4ce1f5..c5aaba7 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidParseWithFormatProviderTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidParseWithFormatProviderTests.cs @@ -15,9 +15,9 @@ public class UuidParseWithFormatProviderTests [SuppressMessage("ReSharper", "RedundantCast")] public static IEnumerable GetFormatProviders() { - yield return (IFormatProvider?)CultureInfo.InvariantCulture; - yield return (IFormatProvider?)new CultureInfo("en-US"); - yield return (IFormatProvider?)null!; + yield return (IFormatProvider?) CultureInfo.InvariantCulture; + yield return (IFormatProvider?) new CultureInfo("en-US"); + yield return (IFormatProvider?) null!; } [Test] @@ -66,7 +66,7 @@ public unsafe void ParseCorrectNString([ValueSource(nameof(GetFormatProviders))] var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -89,7 +89,7 @@ public unsafe void ParseCorrectNSpan([ValueSource(nameof(GetFormatProviders))] I var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -209,7 +209,7 @@ public unsafe void ParseCorrectDString([ValueSource(nameof(GetFormatProviders))] var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -232,7 +232,7 @@ public unsafe void ParseCorrectDSpan([ValueSource(nameof(GetFormatProviders))] I var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -352,7 +352,7 @@ public unsafe void ParseCorrectBString([ValueSource(nameof(GetFormatProviders))] var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -375,7 +375,7 @@ public unsafe void ParseCorrectBSpan([ValueSource(nameof(GetFormatProviders))] I var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -495,7 +495,7 @@ public unsafe void ParseCorrectPString([ValueSource(nameof(GetFormatProviders))] var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -518,7 +518,7 @@ public unsafe void ParseCorrectPSpan([ValueSource(nameof(GetFormatProviders))] I var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -638,7 +638,7 @@ public unsafe void ParseCorrectXString([ValueSource(nameof(GetFormatProviders))] var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); @@ -661,7 +661,7 @@ public unsafe void ParseCorrectXSpan([ValueSource(nameof(GetFormatProviders))] I var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = parsedUuid; + *(Uuid*) pinnedActualBytes = parsedUuid; } Assert.AreEqual(expectedBytes, actualBytes); diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseExactTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseExactTests.cs index 246276b..d6e7380 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseExactTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseExactTests.cs @@ -305,34 +305,54 @@ private unsafe void TryParseExactCorrectStringCorrectFormat( Assert.Multiple(() => { foreach (UuidStringWithBytes correctString in correctStrings) - foreach (string format in correctFormats) { - bool isParsedFromString = Uuid.TryParseExact( - correctString.String, - format, - out Uuid parsedUuidFromString); - bool isParsedBoolFromSpan = Uuid.TryParseExact( - new ReadOnlySpan(correctString.String.ToCharArray()), - new ReadOnlySpan(format.ToCharArray()), - out Uuid parsedUuidFromSpan); - - var actualBytesString = new byte[16]; - var actualBytesSpan = new byte[16]; - fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) + foreach (string format in correctFormats) { - *(Uuid*)pinnedString = parsedUuidFromString; - *(Uuid*)pinnedSpan = parsedUuidFromSpan; + bool isParsedFromString = Uuid.TryParseExact( + correctString.String, + format, + out Uuid parsedUuidFromString); + bool isParsedBoolFromSpan = Uuid.TryParseExact( + new ReadOnlySpan(correctString.String.ToCharArray()), + new ReadOnlySpan(format.ToCharArray()), + out Uuid parsedUuidFromSpan); + + var actualBytesString = new byte[16]; + var actualBytesSpan = new byte[16]; + fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) + { + *(Uuid*) pinnedString = parsedUuidFromString; + *(Uuid*) pinnedSpan = parsedUuidFromSpan; + } + + Assert.True(isParsedFromString); + Assert.True(isParsedBoolFromSpan); + Assert.AreEqual(correctString.Bytes, actualBytesString); + Assert.AreEqual(correctString.Bytes, actualBytesSpan); } - - Assert.True(isParsedFromString); - Assert.True(isParsedBoolFromSpan); - Assert.AreEqual(correctString.Bytes, actualBytesString); - Assert.AreEqual(correctString.Bytes, actualBytesSpan); } }); } - private static readonly byte[] ExpectedEmptyUuidBytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + private static readonly byte[] ExpectedEmptyUuidBytes = + { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }; private unsafe void TryParseExactCorrectStringIncorrectFormat( UuidStringWithBytes[] correctStrings, @@ -341,29 +361,31 @@ private unsafe void TryParseExactCorrectStringIncorrectFormat( Assert.Multiple(() => { foreach (UuidStringWithBytes correctString in correctStrings) - foreach (string incorrectFormat in incorrectFormats) { - bool isParsedFromString = Uuid.TryParseExact( - correctString.String, - incorrectFormat, - out Uuid parsedUuidFromString); - bool isParsedBoolFromSpan = Uuid.TryParseExact( - new ReadOnlySpan(correctString.String.ToCharArray()), - new ReadOnlySpan(incorrectFormat.ToCharArray()), - out Uuid parsedUuidFromSpan); - - var actualBytesString = new byte[16]; - var actualBytesSpan = new byte[16]; - fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) + foreach (string incorrectFormat in incorrectFormats) { - *(Uuid*)pinnedString = parsedUuidFromString; - *(Uuid*)pinnedSpan = parsedUuidFromSpan; + bool isParsedFromString = Uuid.TryParseExact( + correctString.String, + incorrectFormat, + out Uuid parsedUuidFromString); + bool isParsedBoolFromSpan = Uuid.TryParseExact( + new ReadOnlySpan(correctString.String.ToCharArray()), + new ReadOnlySpan(incorrectFormat.ToCharArray()), + out Uuid parsedUuidFromSpan); + + var actualBytesString = new byte[16]; + var actualBytesSpan = new byte[16]; + fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) + { + *(Uuid*) pinnedString = parsedUuidFromString; + *(Uuid*) pinnedSpan = parsedUuidFromSpan; + } + + Assert.False(isParsedFromString); + Assert.False(isParsedBoolFromSpan); + Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesString); + Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesSpan); } - - Assert.False(isParsedFromString); - Assert.False(isParsedBoolFromSpan); - Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesString); - Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesSpan); } }); } @@ -375,29 +397,31 @@ private unsafe void TryParseExactIncorrectStringCorrectFormat( Assert.Multiple(() => { foreach (string brokenString in brokenStrings) - foreach (string correctFormat in correctFormats) { - bool isParsedFromString = Uuid.TryParseExact( - brokenString, - correctFormat, - out Uuid parsedUuidFromString); - bool isParsedBoolFromSpan = Uuid.TryParseExact( - new ReadOnlySpan(brokenString.ToCharArray()), - new ReadOnlySpan(correctFormat.ToCharArray()), - out Uuid parsedUuidFromSpan); - - var actualBytesString = new byte[16]; - var actualBytesSpan = new byte[16]; - fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) + foreach (string correctFormat in correctFormats) { - *(Uuid*)pinnedString = parsedUuidFromString; - *(Uuid*)pinnedSpan = parsedUuidFromSpan; + bool isParsedFromString = Uuid.TryParseExact( + brokenString, + correctFormat, + out Uuid parsedUuidFromString); + bool isParsedBoolFromSpan = Uuid.TryParseExact( + new ReadOnlySpan(brokenString.ToCharArray()), + new ReadOnlySpan(correctFormat.ToCharArray()), + out Uuid parsedUuidFromSpan); + + var actualBytesString = new byte[16]; + var actualBytesSpan = new byte[16]; + fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) + { + *(Uuid*) pinnedString = parsedUuidFromString; + *(Uuid*) pinnedSpan = parsedUuidFromSpan; + } + + Assert.False(isParsedFromString); + Assert.False(isParsedBoolFromSpan); + Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesString); + Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesSpan); } - - Assert.False(isParsedFromString); - Assert.False(isParsedBoolFromSpan); - Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesString); - Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesSpan); } }); } @@ -409,29 +433,31 @@ private unsafe void TryParseExactOtherFormatStringCorrectFormat( Assert.Multiple(() => { foreach (UuidStringWithBytes otherFormatString in otherFormatStrings) - foreach (string correctFormat in correctFormats) { - bool isParsedFromString = Uuid.TryParseExact( - otherFormatString.String, - correctFormat, - out Uuid parsedUuidFromString); - bool isParsedBoolFromSpan = Uuid.TryParseExact( - new ReadOnlySpan(otherFormatString.String.ToCharArray()), - new ReadOnlySpan(correctFormat.ToCharArray()), - out Uuid parsedUuidFromSpan); - - var actualBytesString = new byte[16]; - var actualBytesSpan = new byte[16]; - fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) + foreach (string correctFormat in correctFormats) { - *(Uuid*)pinnedString = parsedUuidFromString; - *(Uuid*)pinnedSpan = parsedUuidFromSpan; + bool isParsedFromString = Uuid.TryParseExact( + otherFormatString.String, + correctFormat, + out Uuid parsedUuidFromString); + bool isParsedBoolFromSpan = Uuid.TryParseExact( + new ReadOnlySpan(otherFormatString.String.ToCharArray()), + new ReadOnlySpan(correctFormat.ToCharArray()), + out Uuid parsedUuidFromSpan); + + var actualBytesString = new byte[16]; + var actualBytesSpan = new byte[16]; + fixed (byte* pinnedString = actualBytesString, pinnedSpan = actualBytesSpan) + { + *(Uuid*) pinnedString = parsedUuidFromString; + *(Uuid*) pinnedSpan = parsedUuidFromSpan; + } + + Assert.False(isParsedFromString); + Assert.False(isParsedBoolFromSpan); + Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesString); + Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesSpan); } - - Assert.False(isParsedFromString); - Assert.False(isParsedBoolFromSpan); - Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesString); - Assert.AreEqual(ExpectedEmptyUuidBytes, actualBytesSpan); } }); } diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseTests.cs index 40dc127..2720a93 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseTests.cs @@ -10,7 +10,7 @@ public class UuidTryParseTests [Test] public void TryParseNullStringShouldFalse() { - bool parsed = Uuid.TryParse((string?)null, out Uuid uuid); + bool parsed = Uuid.TryParse((string?) null, out Uuid uuid); Assert.Multiple(() => { Assert.False(parsed); @@ -316,7 +316,7 @@ private unsafe void TryParseCorrectString(UuidStringWithBytes[] correctStrings) var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = uuid; + *(Uuid*) pinnedActualBytes = uuid; } Assert.True(parsed); @@ -339,7 +339,7 @@ private unsafe void TryParseCorrectSpan(UuidStringWithBytes[] correctStrings) var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = uuid; + *(Uuid*) pinnedActualBytes = uuid; } Assert.True(parsed); diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseUtf8Tests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseUtf8Tests.cs index 8dc4352..1a130df 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseUtf8Tests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseUtf8Tests.cs @@ -11,7 +11,7 @@ public class UuidTryParseUtf8Tests [Test] public void TryParseUtf8NullSpanShouldFalse() { - bool parsed = Uuid.TryParse((ReadOnlySpan)null, out Uuid uuid); + bool parsed = Uuid.TryParse((ReadOnlySpan) null, out Uuid uuid); Assert.Multiple(() => { Assert.False(parsed); @@ -188,7 +188,7 @@ private unsafe void TryParseUtf8CorrectSpan(UuidStringWithBytes[] correctStrings var actualBytes = new byte[16]; fixed (byte* pinnedActualBytes = actualBytes) { - *(Uuid*)pinnedActualBytes = uuid; + *(Uuid*) pinnedActualBytes = uuid; } Assert.True(parsed); diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseWithFormatProviderTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseWithFormatProviderTests.cs index fc4bb8e..b4c9306 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidTryParseWithFormatProviderTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidTryParseWithFormatProviderTests.cs @@ -22,9 +22,9 @@ public static IEnumerable GetFormatProviders() [SuppressMessage("ReSharper", "RedundantCast")] public static IEnumerable GetNullableFormatProviders() { - yield return (IFormatProvider?)CultureInfo.InvariantCulture; - yield return (IFormatProvider?)new CultureInfo("en-US"); - yield return (IFormatProvider?)null!; + yield return (IFormatProvider?) CultureInfo.InvariantCulture; + yield return (IFormatProvider?) new CultureInfo("en-US"); + yield return (IFormatProvider?) null!; } [Test] @@ -328,21 +328,23 @@ private unsafe void TryParseCorrectString(UuidStringWithBytes[] correctStrings) Assert.Multiple(() => { foreach (IFormatProvider? formatProvider in GetNullableFormatProviders()) - foreach (UuidStringWithBytes correctString in correctStrings) { - string stringToParse = correctString.String; - byte[] expectedBytes = correctString.Bytes; + foreach (UuidStringWithBytes correctString in correctStrings) + { + string stringToParse = correctString.String; + byte[] expectedBytes = correctString.Bytes; - bool parsed = Uuid.TryParse(stringToParse, formatProvider, out Uuid uuid); + bool parsed = Uuid.TryParse(stringToParse, formatProvider, out Uuid uuid); - var actualBytes = new byte[16]; - fixed (byte* pinnedActualBytes = actualBytes) - { - *(Uuid*)pinnedActualBytes = uuid; - } + var actualBytes = new byte[16]; + fixed (byte* pinnedActualBytes = actualBytes) + { + *(Uuid*) pinnedActualBytes = uuid; + } - Assert.True(parsed); - Assert.AreEqual(expectedBytes, actualBytes); + Assert.True(parsed); + Assert.AreEqual(expectedBytes, actualBytes); + } } }); } @@ -352,21 +354,23 @@ private unsafe void TryParseCorrectSpan(UuidStringWithBytes[] correctStrings) Assert.Multiple(() => { foreach (IFormatProvider? formatProvider in GetNullableFormatProviders()) - foreach (UuidStringWithBytes correctString in correctStrings) { - var spanToParse = new ReadOnlySpan(correctString.String.ToCharArray()); - byte[] expectedBytes = correctString.Bytes; + foreach (UuidStringWithBytes correctString in correctStrings) + { + var spanToParse = new ReadOnlySpan(correctString.String.ToCharArray()); + byte[] expectedBytes = correctString.Bytes; - bool parsed = Uuid.TryParse(spanToParse, formatProvider, out Uuid uuid); + bool parsed = Uuid.TryParse(spanToParse, formatProvider, out Uuid uuid); - var actualBytes = new byte[16]; - fixed (byte* pinnedActualBytes = actualBytes) - { - *(Uuid*)pinnedActualBytes = uuid; - } + var actualBytes = new byte[16]; + fixed (byte* pinnedActualBytes = actualBytes) + { + *(Uuid*) pinnedActualBytes = uuid; + } - Assert.True(parsed); - Assert.AreEqual(expectedBytes, actualBytes); + Assert.True(parsed); + Assert.AreEqual(expectedBytes, actualBytes); + } } }); } @@ -376,9 +380,11 @@ private void TryParseIncorrectString(string[] incorrectLargeStrings) Assert.Multiple(() => { foreach (IFormatProvider? formatProvider in GetNullableFormatProviders()) - foreach (string largeString in incorrectLargeStrings) { - Assert.False(Uuid.TryParse(largeString, formatProvider, out _)); + foreach (string largeString in incorrectLargeStrings) + { + Assert.False(Uuid.TryParse(largeString, formatProvider, out _)); + } } }); } @@ -388,10 +394,12 @@ private void TryParseIncorrectSpan(string[] incorrectLargeStrings) Assert.Multiple(() => { foreach (IFormatProvider? formatProvider in GetNullableFormatProviders()) - foreach (string largeString in incorrectLargeStrings) { - var largeSpan = new ReadOnlySpan(largeString.ToCharArray()); - Assert.False(Uuid.TryParse(largeSpan, formatProvider, out _)); + foreach (string largeString in incorrectLargeStrings) + { + var largeSpan = new ReadOnlySpan(largeString.ToCharArray()); + Assert.False(Uuid.TryParse(largeSpan, formatProvider, out _)); + } } }); } diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTypeConverterTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTypeConverterTests.cs index deaa6f1..5264d66 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidTypeConverterTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidTypeConverterTests.cs @@ -41,7 +41,7 @@ public void ConvertNotUuidToStringWillCallOverrideToString() Assert.NotNull(actualValue); Assert.IsInstanceOf(actualValue); - Assert.AreEqual(expectedValue, (string?)actualValue); + Assert.AreEqual(expectedValue, (string?) actualValue); Assert.AreEqual(1, notUuid.ToStringCalls); } @@ -56,7 +56,7 @@ public void ConvertToString() Assert.NotNull(actualValue); Assert.IsInstanceOf(actualValue); - Assert.AreEqual(expectedValue, (string?)actualValue); + Assert.AreEqual(expectedValue, (string?) actualValue); } [Test] @@ -71,7 +71,7 @@ public void ConvertToInstanceDescriptor() Assert.NotNull(actualValue); Assert.IsInstanceOf(actualValue); - var actualDescriptor = (InstanceDescriptor?)actualValue; + var actualDescriptor = (InstanceDescriptor?) actualValue; Assert.AreEqual(expectedValue.MemberInfo, actualDescriptor?.MemberInfo); Assert.AreEqual(expectedValue.IsComplete, actualDescriptor?.IsComplete); Assert.AreEqual(expectedValue.Arguments, actualDescriptor?.Arguments); @@ -99,7 +99,7 @@ public void ConvertFromString() Assert.NotNull(actualValue); Assert.IsInstanceOf(actualValue); - Assert.AreEqual(expectedValue, (Uuid)actualValue!); + Assert.AreEqual(expectedValue, (Uuid) actualValue!); } [Test] @@ -114,7 +114,7 @@ public void ConvertFromValidInstanceDescriptor() Assert.NotNull(actualValue); Assert.IsInstanceOf(actualValue); - Assert.AreEqual(expectedValue, (Uuid)actualValue!); + Assert.AreEqual(expectedValue, (Uuid) actualValue!); } [Test] diff --git a/src/Dodo.Primitives.sln b/src/Dodo.Primitives.sln index a817631..d0629e0 100644 --- a/src/Dodo.Primitives.sln +++ b/src/Dodo.Primitives.sln @@ -14,6 +14,11 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{D54C1753-031A-4F30-B892-0C6456E3D7D6}" ProjectSection(SolutionItems) = preProject Directory.Build.props = Directory.Build.props + ..\.editorconfig = ..\.editorconfig + ..\.gitattributes = ..\.gitattributes + ..\.gitignore = ..\.gitignore + ..\global.json = ..\global.json + ..\README.md = ..\README.md EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{021B24DA-238D-4E15-B27D-9DA9191F0ED0}" @@ -46,6 +51,9 @@ Global {B9ECDB73-D6F3-4EC4-B4B4-A7ED2AE781B7} = {56E0CBC4-2555-4231-B28A-A0193DDB9F88} {4C9485A5-FCB5-4361-8C46-C99669D5B22E} = {23740544-1379-49B7-8654-AEC78FB10D75} {288CCF26-65FB-4CC8-932B-01F0A458940A} = {021B24DA-238D-4E15-B27D-9DA9191F0ED0} + {56E0CBC4-2555-4231-B28A-A0193DDB9F88} = {D54C1753-031A-4F30-B892-0C6456E3D7D6} + {23740544-1379-49B7-8654-AEC78FB10D75} = {D54C1753-031A-4F30-B892-0C6456E3D7D6} + {021B24DA-238D-4E15-B27D-9DA9191F0ED0} = {D54C1753-031A-4F30-B892-0C6456E3D7D6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {CD7CBDA7-367E-4456-8A78-BD65663C7340} diff --git a/src/Dodo.Primitives/Dodo.Primitives.csproj b/src/Dodo.Primitives/Dodo.Primitives.csproj index 3778efb..dd4b451 100644 --- a/src/Dodo.Primitives/Dodo.Primitives.csproj +++ b/src/Dodo.Primitives/Dodo.Primitives.csproj @@ -19,7 +19,7 @@ Dodo.Primitives Roman Bukin Dodo Engineering - Copyright 2022 Dodo Engineering + Copyright 2022-2023 Dodo Engineering The main goal of this library is to provide primitive types like Uuid, Hex converter, etc. Uuid Hex Dodo false @@ -45,8 +45,4 @@ - - - - diff --git a/src/Dodo.Primitives/Hex.cs b/src/Dodo.Primitives/Hex.cs index a96b74c..c259396 100644 --- a/src/Dodo.Primitives/Hex.cs +++ b/src/Dodo.Primitives/Hex.cs @@ -90,7 +90,7 @@ public static bool IsHexString(string? possibleHexString) && stringPtr[i + 1] < MaximalChar && (hexByteLow = TableFromHexToBytes[stringPtr[i + 1]]) != 0xFF) { - var resultByte = (byte)((byte)(hexByteHi << 4) | hexByteLow); + var resultByte = (byte) ((byte) (hexByteHi << 4) | hexByteLow); resultPtr[resultIndex] = resultByte; i += 2; resultIndex += 1; @@ -126,7 +126,7 @@ public static bool IsHexString(string? possibleHexString) var resultString = new string('\0', bytes.Length * 2); fixed (char* stringPtr = &resultString.GetPinnableReference()) { - var destUints = (uint*)stringPtr; + var destUints = (uint*) stringPtr; for (var i = 0; i < bytes.Length; i++) { destUints[i] = TableToHex[bytes[i]]; diff --git a/src/Dodo.Primitives/Internal/InternalHexTables.cs b/src/Dodo.Primitives/Internal/InternalHexTables.cs index 72a8891..a406467 100644 --- a/src/Dodo.Primitives/Internal/InternalHexTables.cs +++ b/src/Dodo.Primitives/Internal/InternalHexTables.cs @@ -11,17 +11,17 @@ internal static unsafe class InternalHexTables static InternalHexTables() { - TableToHex = (uint*)Marshal.AllocHGlobal(sizeof(uint) * 256).ToPointer(); + TableToHex = (uint*) Marshal.AllocHGlobal(sizeof(uint) * 256).ToPointer(); for (var i = 0; i < 256; i++) { string chars = Convert.ToString(i, 16).PadLeft(2, '0'); - TableToHex[i] = ((uint)chars[1] << 16) | chars[0]; + TableToHex[i] = ((uint) chars[1] << 16) | chars[0]; } - TableFromHexToBytes = (byte*)Marshal.AllocHGlobal(103).ToPointer(); + TableFromHexToBytes = (byte*) Marshal.AllocHGlobal(103).ToPointer(); for (var i = 0; i < 103; i++) { - TableFromHexToBytes[i] = (char)i switch + TableFromHexToBytes[i] = (char) i switch { '0' => 0x0, '1' => 0x1, diff --git a/src/Dodo.Primitives/SystemTextJsonUuidJsonConverter.cs b/src/Dodo.Primitives/SystemTextJsonUuidJsonConverter.cs index ee4d38b..3779c33 100644 --- a/src/Dodo.Primitives/SystemTextJsonUuidJsonConverter.cs +++ b/src/Dodo.Primitives/SystemTextJsonUuidJsonConverter.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Text.Json; using System.Text.Json.Serialization; @@ -29,4 +30,20 @@ public override void Write( value.TryFormat(outputBuffer, out _, "N"); writer.WriteStringValue(outputBuffer); } + + /// + public override Uuid ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + Debug.Assert(reader.TokenType == JsonTokenType.PropertyName); + return reader.GetUuid(); + } + + /// + public override void WriteAsPropertyName(Utf8JsonWriter writer, Uuid value, JsonSerializerOptions options) + { + // Always will be well-formatted, cuz we allocate exact buffer for output format + Span outputBuffer = stackalloc char[32]; + value.TryFormat(outputBuffer, out _, "N"); + writer.WritePropertyName(outputBuffer); + } } diff --git a/src/Dodo.Primitives/Uuid.cs b/src/Dodo.Primitives/Uuid.cs index 49df101..642716d 100644 --- a/src/Dodo.Primitives/Uuid.cs +++ b/src/Dodo.Primitives/Uuid.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; using System.Text.Json.Serialization; using Dodo.Primitives.Internal; -#if !NET6_0 +#if NET7_0_OR_GREATER using System.Numerics; using System.Runtime.Intrinsics; #endif @@ -24,7 +24,7 @@ public unsafe struct Uuid : IComparable, IComparable, IEquatable -#if !NET6_0 +#if NET7_0_OR_GREATER , ISpanParsable, IComparisonOperators #endif { @@ -61,7 +61,7 @@ static Uuid() /// // ReSharper disable once RedundantDefaultMemberInitializer // ReSharper disable once MemberCanBePrivate.Global - public static readonly Uuid Empty = new(); + public static readonly Uuid Empty = new Uuid(); /// /// Initializes a new instance of the structure by using the specified array of bytes. @@ -126,7 +126,7 @@ public byte[] ToByteArray() /// public bool TryWriteBytes(Span destination) { - if (Unsafe.SizeOf() > (uint)destination.Length) + if (Unsafe.SizeOf() > (uint) destination.Length) { return false; } @@ -155,7 +155,7 @@ public int CompareTo(object? obj) throw new ArgumentException("Object must be of type Uuid.", nameof(obj)); } - var other = (Uuid)obj; + var other = (Uuid) obj; if (other._byte0 != _byte0) { return _byte0 < other._byte0 ? -1 : 1; @@ -344,7 +344,7 @@ public override bool Equals([NotNullWhen(true)] object? obj) { if (obj is Uuid other) { -#if !NET6_0 +#if NET7_0_OR_GREATER if (Vector128.IsHardwareAccelerated) { return Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in this))) @@ -368,7 +368,7 @@ public override bool Equals([NotNullWhen(true)] object? obj) /// if is equal to this instance; otherwise, . public bool Equals(Uuid other) { -#if !NET6_0 +#if NET7_0_OR_GREATER if (Vector128.IsHardwareAccelerated) { return Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in this))) @@ -400,7 +400,7 @@ public override int GetHashCode() /// if and are equal; otherwise, . public static bool operator ==(Uuid left, Uuid right) { -#if !NET6_0 +#if NET7_0_OR_GREATER if (Vector128.IsHardwareAccelerated) { return Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in left))) @@ -425,7 +425,7 @@ public override int GetHashCode() /// public static bool operator !=(Uuid left, Uuid right) { -#if !NET6_0 +#if NET7_0_OR_GREATER if (Vector128.IsHardwareAccelerated) { return Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in left))) @@ -457,7 +457,7 @@ public override int GetHashCode() public bool TryFormat( Span destination, out int charsWritten, -#if !NET6_0 +#if NET7_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif ReadOnlySpan format, @@ -474,93 +474,93 @@ public bool TryFormat( return false; } - switch ((char)(format[0] | 0x20)) + switch ((char) (format[0] | 0x20)) { case 'n': - { - if (destination.Length < 32) { - charsWritten = 0; - return false; - } + if (destination.Length < 32) + { + charsWritten = 0; + return false; + } - fixed (char* uuidChars = &destination.GetPinnableReference()) - { - FormatN(uuidChars); - } + fixed (char* uuidChars = &destination.GetPinnableReference()) + { + FormatN(uuidChars); + } - charsWritten = 32; - return true; - } + charsWritten = 32; + return true; + } case 'd': - { - if (destination.Length < 36) { - charsWritten = 0; - return false; - } + if (destination.Length < 36) + { + charsWritten = 0; + return false; + } - fixed (char* uuidChars = &destination.GetPinnableReference()) - { - FormatD(uuidChars); - } + fixed (char* uuidChars = &destination.GetPinnableReference()) + { + FormatD(uuidChars); + } - charsWritten = 36; - return true; - } + charsWritten = 36; + return true; + } case 'b': - { - if (destination.Length < 38) { - charsWritten = 0; - return false; - } + if (destination.Length < 38) + { + charsWritten = 0; + return false; + } - fixed (char* uuidChars = &destination.GetPinnableReference()) - { - FormatB(uuidChars); - } + fixed (char* uuidChars = &destination.GetPinnableReference()) + { + FormatB(uuidChars); + } - charsWritten = 38; - return true; - } + charsWritten = 38; + return true; + } case 'p': - { - if (destination.Length < 38) { - charsWritten = 0; - return false; - } + if (destination.Length < 38) + { + charsWritten = 0; + return false; + } - fixed (char* uuidChars = &destination.GetPinnableReference()) - { - FormatP(uuidChars); - } + fixed (char* uuidChars = &destination.GetPinnableReference()) + { + FormatP(uuidChars); + } - charsWritten = 38; - return true; - } + charsWritten = 38; + return true; + } case 'x': - { - if (destination.Length < 68) { - charsWritten = 0; - return false; - } + if (destination.Length < 68) + { + charsWritten = 0; + return false; + } - fixed (char* uuidChars = &destination.GetPinnableReference()) - { - FormatX(uuidChars); - } + fixed (char* uuidChars = &destination.GetPinnableReference()) + { + FormatX(uuidChars); + } - charsWritten = 68; - return true; - } + charsWritten = 68; + return true; + } default: - { - charsWritten = 0; - return false; - } + { + charsWritten = 0; + return false; + } } } @@ -581,7 +581,7 @@ public bool TryFormat( public bool TryFormat( Span destination, out int charsWritten, -#if !NET6_0 +#if NET7_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif ReadOnlySpan format = default) @@ -597,93 +597,93 @@ public bool TryFormat( return false; } - switch ((char)(format[0] | 0x20)) + switch ((char) (format[0] | 0x20)) { case 'n': - { - if (destination.Length < 32) { - charsWritten = 0; - return false; - } + if (destination.Length < 32) + { + charsWritten = 0; + return false; + } - fixed (char* uuidChars = &destination.GetPinnableReference()) - { - FormatN(uuidChars); - } + fixed (char* uuidChars = &destination.GetPinnableReference()) + { + FormatN(uuidChars); + } - charsWritten = 32; - return true; - } + charsWritten = 32; + return true; + } case 'd': - { - if (destination.Length < 36) { - charsWritten = 0; - return false; - } + if (destination.Length < 36) + { + charsWritten = 0; + return false; + } - fixed (char* uuidChars = &destination.GetPinnableReference()) - { - FormatD(uuidChars); - } + fixed (char* uuidChars = &destination.GetPinnableReference()) + { + FormatD(uuidChars); + } - charsWritten = 36; - return true; - } + charsWritten = 36; + return true; + } case 'b': - { - if (destination.Length < 38) { - charsWritten = 0; - return false; - } + if (destination.Length < 38) + { + charsWritten = 0; + return false; + } - fixed (char* uuidChars = &destination.GetPinnableReference()) - { - FormatB(uuidChars); - } + fixed (char* uuidChars = &destination.GetPinnableReference()) + { + FormatB(uuidChars); + } - charsWritten = 38; - return true; - } + charsWritten = 38; + return true; + } case 'p': - { - if (destination.Length < 38) { - charsWritten = 0; - return false; - } + if (destination.Length < 38) + { + charsWritten = 0; + return false; + } - fixed (char* uuidChars = &destination.GetPinnableReference()) - { - FormatP(uuidChars); - } + fixed (char* uuidChars = &destination.GetPinnableReference()) + { + FormatP(uuidChars); + } - charsWritten = 38; - return true; - } + charsWritten = 38; + return true; + } case 'x': - { - if (destination.Length < 68) { - charsWritten = 0; - return false; - } + if (destination.Length < 68) + { + charsWritten = 0; + return false; + } - fixed (char* uuidChars = &destination.GetPinnableReference()) - { - FormatX(uuidChars); - } + fixed (char* uuidChars = &destination.GetPinnableReference()) + { + FormatX(uuidChars); + } - charsWritten = 68; - return true; - } + charsWritten = 68; + return true; + } default: - { - charsWritten = 0; - return false; - } + { + charsWritten = 0; + return false; + } } } @@ -705,7 +705,7 @@ public override string ToString() /// /// The value of this , represented as a series of lowercase hexadecimal digits in the specified format. public string ToString( -#if !NET6_0 +#if NET7_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif string? format) @@ -729,7 +729,7 @@ public string ToString( /// "B", "P", or "X". /// public string ToString( -#if !NET6_0 +#if NET7_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif string? format, @@ -748,58 +748,58 @@ public string ToString( "Format string can be only \"N\", \"n\", \"D\", \"d\", \"P\", \"p\", \"B\", \"b\", \"X\" or \"x\"."); } - switch ((char)(format[0] | 0x20)) + switch ((char) (format[0] | 0x20)) { case 'n': - { - var uuidString = new string('\0', 32); - fixed (char* uuidChars = &uuidString.GetPinnableReference()) { - FormatN(uuidChars); - } + var uuidString = new string('\0', 32); + fixed (char* uuidChars = &uuidString.GetPinnableReference()) + { + FormatN(uuidChars); + } - return uuidString; - } + return uuidString; + } case 'd': - { - var uuidString = new string('\0', 36); - fixed (char* uuidChars = &uuidString.GetPinnableReference()) { - FormatD(uuidChars); - } + var uuidString = new string('\0', 36); + fixed (char* uuidChars = &uuidString.GetPinnableReference()) + { + FormatD(uuidChars); + } - return uuidString; - } + return uuidString; + } case 'b': - { - var uuidString = new string('\0', 38); - fixed (char* uuidChars = &uuidString.GetPinnableReference()) { - FormatB(uuidChars); - } + var uuidString = new string('\0', 38); + fixed (char* uuidChars = &uuidString.GetPinnableReference()) + { + FormatB(uuidChars); + } - return uuidString; - } + return uuidString; + } case 'p': - { - var uuidString = new string('\0', 38); - fixed (char* uuidChars = &uuidString.GetPinnableReference()) { - FormatP(uuidChars); - } + var uuidString = new string('\0', 38); + fixed (char* uuidChars = &uuidString.GetPinnableReference()) + { + FormatP(uuidChars); + } - return uuidString; - } + return uuidString; + } case 'x': - { - var uuidString = new string('\0', 68); - fixed (char* uuidChars = &uuidString.GetPinnableReference()) { - FormatX(uuidChars); - } + var uuidString = new string('\0', 68); + fixed (char* uuidChars = &uuidString.GetPinnableReference()) + { + FormatX(uuidChars); + } - return uuidString; - } + return uuidString; + } default: throw new FormatException( "Format string can be only \"N\", \"n\", \"D\", \"d\", \"P\", \"p\", \"B\", \"b\", \"X\" or \"x\"."); @@ -810,7 +810,7 @@ public string ToString( private void FormatN(char* dest) { // dddddddddddddddddddddddddddddddd - var destUints = (uint*)dest; + var destUints = (uint*) dest; destUints[0] = TableToHex[_byte0]; destUints[1] = TableToHex[_byte1]; destUints[2] = TableToHex[_byte2]; @@ -833,8 +833,8 @@ private void FormatN(char* dest) private void FormatD(char* dest) { // dddddddd-dddd-dddd-dddd-dddddddddddd - var destUints = (uint*)dest; - var destUintsAsChars = (char**)&destUints; + var destUints = (uint*) dest; + var destUintsAsChars = (char**) &destUints; dest[8] = dest[13] = dest[18] = dest[23] = '-'; destUints[0] = TableToHex[_byte0]; destUints[1] = TableToHex[_byte1]; @@ -859,8 +859,8 @@ private void FormatD(char* dest) private void FormatB(char* dest) { // {dddddddd-dddd-dddd-dddd-dddddddddddd} - var destUints = (uint*)dest; - var destUintsAsChars = (char**)&destUints; + var destUints = (uint*) dest; + var destUintsAsChars = (char**) &destUints; dest[0] = '{'; dest[9] = dest[14] = dest[19] = dest[24] = '-'; dest[37] = '}'; @@ -887,8 +887,8 @@ private void FormatB(char* dest) private void FormatP(char* dest) { // (dddddddd-dddd-dddd-dddd-dddddddddddd) - var destUints = (uint*)dest; - var destUintsAsChars = (char**)&destUints; + var destUints = (uint*) dest; + var destUintsAsChars = (char**) &destUints; dest[0] = '('; dest[9] = dest[14] = dest[19] = dest[24] = '-'; dest[37] = ')'; @@ -919,8 +919,8 @@ private void FormatP(char* dest) private void FormatX(char* dest) { // {0xdddddddd,0xdddd,0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}} - var destUints = (uint*)dest; - var uintDestAsChars = (char**)&destUints; + var destUints = (uint*) dest; + var uintDestAsChars = (char**) &destUints; dest[0] = '{'; dest[11] = dest[18] = dest[31] = dest[36] = dest[41] = dest[46] = dest[51] = dest[56] = dest[61] = ','; destUints[6] = destUints[16] = destUints[21] = destUints[26] = destUints[31] = ZeroX; // 0x @@ -955,7 +955,7 @@ public Guid ToGuidByteLayout() { var result = new Guid(); Guid* resultPtr = &result; - var resultPtrBytes = (byte*)resultPtr; + var resultPtrBytes = (byte*) resultPtr; resultPtrBytes[0] = _byte0; resultPtrBytes[1] = _byte1; resultPtrBytes[2] = _byte2; @@ -984,7 +984,7 @@ public Guid ToGuidStringLayout() { var result = new Guid(); Guid* resultPtr = &result; - var resultPtrBytes = (byte*)resultPtr; + var resultPtrBytes = (byte*) resultPtr; resultPtrBytes[0] = _byte3; resultPtrBytes[1] = _byte2; resultPtrBytes[2] = _byte1; @@ -1014,7 +1014,7 @@ public Uuid(string input) { ArgumentNullException.ThrowIfNull(input); var result = new Uuid(); - var resultPtr = (byte*)&result; + var resultPtr = (byte*) &result; fixed (char* uuidStringPtr = &input.GetPinnableReference()) { ParseWithExceptions(new ReadOnlySpan(uuidStringPtr, input.Length), uuidStringPtr, resultPtr); @@ -1037,7 +1037,7 @@ public Uuid(ReadOnlySpan input) } var result = new Uuid(); - var resultPtr = (byte*)&result; + var resultPtr = (byte*) &result; fixed (char* uuidStringPtr = &input.GetPinnableReference()) { ParseWithExceptions(input, uuidStringPtr, resultPtr); @@ -1057,7 +1057,7 @@ public static Uuid Parse(string input) { ArgumentNullException.ThrowIfNull(input); var result = new Uuid(); - var resultPtr = (byte*)&result; + var resultPtr = (byte*) &result; fixed (char* uuidStringPtr = &input.GetPinnableReference()) { ParseWithExceptions(new ReadOnlySpan(uuidStringPtr, input.Length), uuidStringPtr, resultPtr); @@ -1080,7 +1080,7 @@ public static Uuid Parse(ReadOnlySpan input) } var result = new Uuid(); - var resultPtr = (byte*)&result; + var resultPtr = (byte*) &result; fixed (char* uuidStringPtr = &input.GetPinnableReference()) { ParseWithExceptions(input, uuidStringPtr, resultPtr); @@ -1103,7 +1103,7 @@ public static Uuid Parse(ReadOnlySpan input) /// is not in the format specified by . public static Uuid ParseExact( string input, -#if !NET6_0 +#if NET7_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif string format) @@ -1112,59 +1112,59 @@ public static Uuid ParseExact( ArgumentNullException.ThrowIfNull(format); var result = new Uuid(); - var resultPtr = (byte*)&result; - switch ((char)(format[0] | 0x20)) + var resultPtr = (byte*) &result; + switch ((char) (format[0] | 0x20)) { case 'n': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - ParseWithExceptionsN((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + ParseWithExceptionsN((uint) input.Length, uuidStringPtr, resultPtr); + } - return result; - } + return result; + } case 'd': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - ParseWithExceptionsD((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + ParseWithExceptionsD((uint) input.Length, uuidStringPtr, resultPtr); + } - return result; - } + return result; + } case 'b': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - ParseWithExceptionsB((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + ParseWithExceptionsB((uint) input.Length, uuidStringPtr, resultPtr); + } - return result; - } + return result; + } case 'p': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - ParseWithExceptionsP((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + ParseWithExceptionsP((uint) input.Length, uuidStringPtr, resultPtr); + } - return result; - } + return result; + } case 'x': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - ParseWithExceptionsX((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + ParseWithExceptionsX((uint) input.Length, uuidStringPtr, resultPtr); + } - return result; - } + return result; + } default: - { - throw new FormatException( - "Format string can be only \"N\", \"n\", \"D\", \"d\", \"P\", \"p\", \"B\", \"b\", \"X\" or \"x\"."); - } + { + throw new FormatException( + "Format string can be only \"N\", \"n\", \"D\", \"d\", \"P\", \"p\", \"B\", \"b\", \"X\" or \"x\"."); + } } } @@ -1181,7 +1181,7 @@ public static Uuid ParseExact( /// is not in the format specified by . public static Uuid ParseExact( ReadOnlySpan input, -#if !NET6_0 +#if NET7_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif ReadOnlySpan format) @@ -1198,59 +1198,59 @@ public static Uuid ParseExact( } var result = new Uuid(); - var resultPtr = (byte*)&result; - switch ((char)(format[0] | 0x20)) + var resultPtr = (byte*) &result; + switch ((char) (format[0] | 0x20)) { case 'n': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - ParseWithExceptionsN((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + ParseWithExceptionsN((uint) input.Length, uuidStringPtr, resultPtr); + } - return result; - } + return result; + } case 'd': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - ParseWithExceptionsD((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + ParseWithExceptionsD((uint) input.Length, uuidStringPtr, resultPtr); + } - return result; - } + return result; + } case 'b': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - ParseWithExceptionsB((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + ParseWithExceptionsB((uint) input.Length, uuidStringPtr, resultPtr); + } - return result; - } + return result; + } case 'p': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - ParseWithExceptionsP((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + ParseWithExceptionsP((uint) input.Length, uuidStringPtr, resultPtr); + } - return result; - } + return result; + } case 'x': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - ParseWithExceptionsX((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + ParseWithExceptionsX((uint) input.Length, uuidStringPtr, resultPtr); + } - return result; - } + return result; + } default: - { - throw new FormatException( - "Format string can be only \"N\", \"n\", \"D\", \"d\", \"P\", \"p\", \"B\", \"b\", \"X\" or \"x\"."); - } + { + throw new FormatException( + "Format string can be only \"N\", \"n\", \"D\", \"d\", \"P\", \"p\", \"B\", \"b\", \"X\" or \"x\"."); + } } } @@ -1273,7 +1273,7 @@ public static bool TryParse([NotNullWhen(true)] string? input, out Uuid output) } var result = new Uuid(); - var resultPtr = (byte*)&result; + var resultPtr = (byte*) &result; fixed (char* uuidStringPtr = &input.GetPinnableReference()) { if (ParseWithoutExceptions(input.AsSpan(), uuidStringPtr, resultPtr)) @@ -1307,7 +1307,7 @@ public static bool TryParse(ReadOnlySpan input, out Uuid output) } var result = new Uuid(); - var resultPtr = (byte*)&result; + var resultPtr = (byte*) &result; fixed (char* uuidStringPtr = &input.GetPinnableReference()) { if (ParseWithoutExceptions(input, uuidStringPtr, resultPtr)) @@ -1341,7 +1341,7 @@ public static bool TryParse(ReadOnlySpan uuidUtf8String, out Uuid output) } var result = new Uuid(); - var resultPtr = (byte*)&result; + var resultPtr = (byte*) &result; fixed (byte* uuidUtf8StringPtr = &uuidUtf8String.GetPinnableReference()) { if (ParseWithoutExceptionsUtf8(uuidUtf8String, uuidUtf8StringPtr, resultPtr)) @@ -1372,68 +1372,68 @@ public static bool TryParse(ReadOnlySpan uuidUtf8String, out Uuid output) /// if the parse operation was successful; otherwise, . public static bool TryParseExact( [NotNullWhen(true)] string? input, -#if !NET6_0 +#if NET7_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif string format, out Uuid output) { - if (input == null || format?.Length != 1) + if (input == null || string.IsNullOrEmpty(format) || format.Length != 1) { output = default; return false; } var result = new Uuid(); - var resultPtr = (byte*)&result; + var resultPtr = (byte*) &result; var parsed = false; - switch ((char)(format[0] | 0x20)) + switch ((char) (format[0] | 0x20)) { case 'd': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - parsed = ParseWithoutExceptionsD((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + parsed = ParseWithoutExceptionsD((uint) input.Length, uuidStringPtr, resultPtr); + } - break; - } + break; + } case 'n': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - parsed = ParseWithoutExceptionsN((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + parsed = ParseWithoutExceptionsN((uint) input.Length, uuidStringPtr, resultPtr); + } - break; - } + break; + } case 'b': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - parsed = ParseWithoutExceptionsB((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + parsed = ParseWithoutExceptionsB((uint) input.Length, uuidStringPtr, resultPtr); + } - break; - } + break; + } case 'p': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - parsed = ParseWithoutExceptionsP((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + parsed = ParseWithoutExceptionsP((uint) input.Length, uuidStringPtr, resultPtr); + } - break; - } + break; + } case 'x': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - parsed = ParseWithoutExceptionsX((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + parsed = ParseWithoutExceptionsX((uint) input.Length, uuidStringPtr, resultPtr); + } - break; - } + break; + } } if (parsed) @@ -1463,7 +1463,7 @@ public static bool TryParseExact( /// if the parse operation was successful; otherwise, . public static bool TryParseExact( ReadOnlySpan input, -#if !NET6_0 +#if NET7_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif ReadOnlySpan format, @@ -1476,55 +1476,55 @@ public static bool TryParseExact( } var result = new Uuid(); - var resultPtr = (byte*)&result; + var resultPtr = (byte*) &result; var parsed = false; - switch ((char)(format[0] | 0x20)) + switch ((char) (format[0] | 0x20)) { case 'd': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - parsed = ParseWithoutExceptionsD((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + parsed = ParseWithoutExceptionsD((uint) input.Length, uuidStringPtr, resultPtr); + } - break; - } + break; + } case 'n': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - parsed = ParseWithoutExceptionsN((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + parsed = ParseWithoutExceptionsN((uint) input.Length, uuidStringPtr, resultPtr); + } - break; - } + break; + } case 'b': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - parsed = ParseWithoutExceptionsB((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + parsed = ParseWithoutExceptionsB((uint) input.Length, uuidStringPtr, resultPtr); + } - break; - } + break; + } case 'p': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - parsed = ParseWithoutExceptionsP((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + parsed = ParseWithoutExceptionsP((uint) input.Length, uuidStringPtr, resultPtr); + } - break; - } + break; + } case 'x': - { - fixed (char* uuidStringPtr = &input.GetPinnableReference()) { - parsed = ParseWithoutExceptionsX((uint)input.Length, uuidStringPtr, resultPtr); - } + fixed (char* uuidStringPtr = &input.GetPinnableReference()) + { + parsed = ParseWithoutExceptionsX((uint) input.Length, uuidStringPtr, resultPtr); + } - break; - } + break; + } } if (parsed) @@ -1539,7 +1539,7 @@ public static bool TryParseExact( private static bool ParseWithoutExceptions(ReadOnlySpan uuidString, char* uuidStringPtr, byte* resultPtr) { - var length = (uint)uuidString.Length; + var length = (uint) uuidString.Length; if (length == 0u) { return false; @@ -1551,21 +1551,21 @@ private static bool ParseWithoutExceptions(ReadOnlySpan uuidString, char* switch (uuidString[0]) { case '(': - { - return ParseWithoutExceptionsP(length, uuidStringPtr, resultPtr); - } + { + return ParseWithoutExceptionsP(length, uuidStringPtr, resultPtr); + } case '{': - { - return uuidString.Contains(dashSpan, StringComparison.Ordinal) - ? ParseWithoutExceptionsB(length, uuidStringPtr, resultPtr) - : ParseWithoutExceptionsX(length, uuidStringPtr, resultPtr); - } + { + return uuidString.Contains(dashSpan, StringComparison.Ordinal) + ? ParseWithoutExceptionsB(length, uuidStringPtr, resultPtr) + : ParseWithoutExceptionsX(length, uuidStringPtr, resultPtr); + } default: - { - return uuidString.Contains(dashSpan, StringComparison.Ordinal) - ? ParseWithoutExceptionsD(length, uuidStringPtr, resultPtr) - : ParseWithoutExceptionsN(length, uuidStringPtr, resultPtr); - } + { + return uuidString.Contains(dashSpan, StringComparison.Ordinal) + ? ParseWithoutExceptionsD(length, uuidStringPtr, resultPtr) + : ParseWithoutExceptionsN(length, uuidStringPtr, resultPtr); + } } } @@ -1721,25 +1721,25 @@ private static bool ParseWithoutExceptionsX(uint uuidStringLength, char* uuidStr private static bool ParseWithoutExceptionsUtf8(ReadOnlySpan uuidUtf8String, byte* uuidUtf8StringPtr, byte* resultPtr) { - var length = (uint)uuidUtf8String.Length; + var length = (uint) uuidUtf8String.Length; switch (uuidUtf8String[0]) { case Utf8LeftParenthesis: // ( - { - return ParseWithoutExceptionsPUtf8(length, uuidUtf8StringPtr, resultPtr); - } + { + return ParseWithoutExceptionsPUtf8(length, uuidUtf8StringPtr, resultPtr); + } case Utf8LeftCurlyBracket: - { - return uuidUtf8String.Contains(Utf8HyphenMinus) - ? ParseWithoutExceptionsBUtf8(length, uuidUtf8StringPtr, resultPtr) - : ParseWithoutExceptionsXUtf8(length, uuidUtf8StringPtr, resultPtr); - } + { + return uuidUtf8String.Contains(Utf8HyphenMinus) + ? ParseWithoutExceptionsBUtf8(length, uuidUtf8StringPtr, resultPtr) + : ParseWithoutExceptionsXUtf8(length, uuidUtf8StringPtr, resultPtr); + } default: - { - return uuidUtf8String.IndexOf(Utf8HyphenMinus) >= 0 - ? ParseWithoutExceptionsDUtf8(length, uuidUtf8StringPtr, resultPtr) - : ParseWithoutExceptionsNUtf8(length, uuidUtf8StringPtr, resultPtr); - } + { + return uuidUtf8String.IndexOf(Utf8HyphenMinus) >= 0 + ? ParseWithoutExceptionsDUtf8(length, uuidUtf8StringPtr, resultPtr) + : ParseWithoutExceptionsNUtf8(length, uuidUtf8StringPtr, resultPtr); + } } } @@ -1860,7 +1860,7 @@ private static bool ParseWithoutExceptionsXUtf8(uint uuidStringLength, byte* uui private static void ParseWithExceptions(ReadOnlySpan uuidString, char* uuidStringPtr, byte* resultPtr) { - var length = (uint)uuidString.Length; + var length = (uint) uuidString.Length; if (length == 0u) { throw new FormatException("Unrecognized Uuid format."); @@ -1872,32 +1872,32 @@ private static void ParseWithExceptions(ReadOnlySpan uuidString, char* uui switch (uuidStringPtr[0]) { case '(': - { - ParseWithExceptionsP(length, uuidStringPtr, resultPtr); - break; - } - case '{': - { - if (uuidString.Contains(dashSpan, StringComparison.Ordinal)) { - ParseWithExceptionsB(length, uuidStringPtr, resultPtr); + ParseWithExceptionsP(length, uuidStringPtr, resultPtr); break; } + case '{': + { + if (uuidString.Contains(dashSpan, StringComparison.Ordinal)) + { + ParseWithExceptionsB(length, uuidStringPtr, resultPtr); + break; + } - ParseWithExceptionsX(length, uuidStringPtr, resultPtr); - break; - } + ParseWithExceptionsX(length, uuidStringPtr, resultPtr); + break; + } default: - { - if (uuidString.Contains(dashSpan, StringComparison.Ordinal)) { - ParseWithExceptionsD(length, uuidStringPtr, resultPtr); + if (uuidString.Contains(dashSpan, StringComparison.Ordinal)) + { + ParseWithExceptionsD(length, uuidStringPtr, resultPtr); + break; + } + + ParseWithExceptionsN(length, uuidStringPtr, resultPtr); break; } - - ParseWithExceptionsN(length, uuidStringPtr, resultPtr); - break; - } } } @@ -2064,112 +2064,112 @@ private static bool TryParsePtrN(char* value, byte* resultPtr) && value[1] < MaximalChar && (lo = TableFromHexToBytes[value[1]]) != 0xFF) { - resultPtr[0] = (byte)((byte)(hi << 4) | lo); + resultPtr[0] = (byte) ((byte) (hi << 4) | lo); // 1 byte if (value[2] < MaximalChar && (hi = TableFromHexToBytes[value[2]]) != 0xFF && value[3] < MaximalChar && (lo = TableFromHexToBytes[value[3]]) != 0xFF) { - resultPtr[1] = (byte)((byte)(hi << 4) | lo); + resultPtr[1] = (byte) ((byte) (hi << 4) | lo); // 2 byte if (value[4] < MaximalChar && (hi = TableFromHexToBytes[value[4]]) != 0xFF && value[5] < MaximalChar && (lo = TableFromHexToBytes[value[5]]) != 0xFF) { - resultPtr[2] = (byte)((byte)(hi << 4) | lo); + resultPtr[2] = (byte) ((byte) (hi << 4) | lo); // 3 byte if (value[6] < MaximalChar && (hi = TableFromHexToBytes[value[6]]) != 0xFF && value[7] < MaximalChar && (lo = TableFromHexToBytes[value[7]]) != 0xFF) { - resultPtr[3] = (byte)((byte)(hi << 4) | lo); + resultPtr[3] = (byte) ((byte) (hi << 4) | lo); // 4 byte if (value[8] < MaximalChar && (hi = TableFromHexToBytes[value[8]]) != 0xFF && value[9] < MaximalChar && (lo = TableFromHexToBytes[value[9]]) != 0xFF) { - resultPtr[4] = (byte)((byte)(hi << 4) | lo); + resultPtr[4] = (byte) ((byte) (hi << 4) | lo); // 5 byte if (value[10] < MaximalChar && (hi = TableFromHexToBytes[value[10]]) != 0xFF && value[11] < MaximalChar && (lo = TableFromHexToBytes[value[11]]) != 0xFF) { - resultPtr[5] = (byte)((byte)(hi << 4) | lo); + resultPtr[5] = (byte) ((byte) (hi << 4) | lo); // 6 byte if (value[12] < MaximalChar && (hi = TableFromHexToBytes[value[12]]) != 0xFF && value[13] < MaximalChar && (lo = TableFromHexToBytes[value[13]]) != 0xFF) { - resultPtr[6] = (byte)((byte)(hi << 4) | lo); + resultPtr[6] = (byte) ((byte) (hi << 4) | lo); // 7 byte if (value[14] < MaximalChar && (hi = TableFromHexToBytes[value[14]]) != 0xFF && value[15] < MaximalChar && (lo = TableFromHexToBytes[value[15]]) != 0xFF) { - resultPtr[7] = (byte)((byte)(hi << 4) | lo); + resultPtr[7] = (byte) ((byte) (hi << 4) | lo); // 8 byte if (value[16] < MaximalChar && (hi = TableFromHexToBytes[value[16]]) != 0xFF && value[17] < MaximalChar && (lo = TableFromHexToBytes[value[17]]) != 0xFF) { - resultPtr[8] = (byte)((byte)(hi << 4) | lo); + resultPtr[8] = (byte) ((byte) (hi << 4) | lo); // 9 byte if (value[18] < MaximalChar && (hi = TableFromHexToBytes[value[18]]) != 0xFF && value[19] < MaximalChar && (lo = TableFromHexToBytes[value[19]]) != 0xFF) { - resultPtr[9] = (byte)((byte)(hi << 4) | lo); + resultPtr[9] = (byte) ((byte) (hi << 4) | lo); // 10 byte if (value[20] < MaximalChar && (hi = TableFromHexToBytes[value[20]]) != 0xFF && value[21] < MaximalChar && (lo = TableFromHexToBytes[value[21]]) != 0xFF) { - resultPtr[10] = (byte)((byte)(hi << 4) | lo); + resultPtr[10] = (byte) ((byte) (hi << 4) | lo); // 11 byte if (value[22] < MaximalChar && (hi = TableFromHexToBytes[value[22]]) != 0xFF && value[23] < MaximalChar && (lo = TableFromHexToBytes[value[23]]) != 0xFF) { - resultPtr[11] = (byte)((byte)(hi << 4) | lo); + resultPtr[11] = (byte) ((byte) (hi << 4) | lo); // 12 byte if (value[24] < MaximalChar && (hi = TableFromHexToBytes[value[24]]) != 0xFF && value[25] < MaximalChar && (lo = TableFromHexToBytes[value[25]]) != 0xFF) { - resultPtr[12] = (byte)((byte)(hi << 4) | lo); + resultPtr[12] = (byte) ((byte) (hi << 4) | lo); // 13 byte if (value[26] < MaximalChar && (hi = TableFromHexToBytes[value[26]]) != 0xFF && value[27] < MaximalChar && (lo = TableFromHexToBytes[value[27]]) != 0xFF) { - resultPtr[13] = (byte)((byte)(hi << 4) | lo); + resultPtr[13] = (byte) ((byte) (hi << 4) | lo); // 14 byte if (value[28] < MaximalChar && (hi = TableFromHexToBytes[value[28]]) != 0xFF && value[29] < MaximalChar && (lo = TableFromHexToBytes[value[29]]) != 0xFF) { - resultPtr[14] = (byte)((byte)(hi << 4) | lo); + resultPtr[14] = (byte) ((byte) (hi << 4) | lo); // 15 byte if (value[30] < MaximalChar && (hi = TableFromHexToBytes[value[30]]) != 0xFF && value[31] < MaximalChar && (lo = TableFromHexToBytes[value[31]]) != 0xFF) { - resultPtr[15] = (byte)((byte)(hi << 4) | lo); + resultPtr[15] = (byte) ((byte) (hi << 4) | lo); return true; } } @@ -2203,28 +2203,28 @@ private static bool TryParsePtrD(char* value, byte* resultPtr) && value[1] < MaximalChar && (lo = TableFromHexToBytes[value[1]]) != 0xFF) { - resultPtr[0] = (byte)((byte)(hi << 4) | lo); + resultPtr[0] = (byte) ((byte) (hi << 4) | lo); // 1 byte if (value[2] < MaximalChar && (hi = TableFromHexToBytes[value[2]]) != 0xFF && value[3] < MaximalChar && (lo = TableFromHexToBytes[value[3]]) != 0xFF) { - resultPtr[1] = (byte)((byte)(hi << 4) | lo); + resultPtr[1] = (byte) ((byte) (hi << 4) | lo); // 2 byte if (value[4] < MaximalChar && (hi = TableFromHexToBytes[value[4]]) != 0xFF && value[5] < MaximalChar && (lo = TableFromHexToBytes[value[5]]) != 0xFF) { - resultPtr[2] = (byte)((byte)(hi << 4) | lo); + resultPtr[2] = (byte) ((byte) (hi << 4) | lo); // 3 byte if (value[6] < MaximalChar && (hi = TableFromHexToBytes[value[6]]) != 0xFF && value[7] < MaximalChar && (lo = TableFromHexToBytes[value[7]]) != 0xFF) { - resultPtr[3] = (byte)((byte)(hi << 4) | lo); + resultPtr[3] = (byte) ((byte) (hi << 4) | lo); // value[8] == '-' @@ -2234,14 +2234,14 @@ private static bool TryParsePtrD(char* value, byte* resultPtr) && value[10] < MaximalChar && (lo = TableFromHexToBytes[value[10]]) != 0xFF) { - resultPtr[4] = (byte)((byte)(hi << 4) | lo); + resultPtr[4] = (byte) ((byte) (hi << 4) | lo); // 5 byte if (value[11] < MaximalChar && (hi = TableFromHexToBytes[value[11]]) != 0xFF && value[12] < MaximalChar && (lo = TableFromHexToBytes[value[12]]) != 0xFF) { - resultPtr[5] = (byte)((byte)(hi << 4) | lo); + resultPtr[5] = (byte) ((byte) (hi << 4) | lo); // value[13] == '-' @@ -2251,14 +2251,14 @@ private static bool TryParsePtrD(char* value, byte* resultPtr) && value[15] < MaximalChar && (lo = TableFromHexToBytes[value[15]]) != 0xFF) { - resultPtr[6] = (byte)((byte)(hi << 4) | lo); + resultPtr[6] = (byte) ((byte) (hi << 4) | lo); // 7 byte if (value[16] < MaximalChar && (hi = TableFromHexToBytes[value[16]]) != 0xFF && value[17] < MaximalChar && (lo = TableFromHexToBytes[value[17]]) != 0xFF) { - resultPtr[7] = (byte)((byte)(hi << 4) | lo); + resultPtr[7] = (byte) ((byte) (hi << 4) | lo); // value[18] == '-' @@ -2268,14 +2268,14 @@ private static bool TryParsePtrD(char* value, byte* resultPtr) && value[20] < MaximalChar && (lo = TableFromHexToBytes[value[20]]) != 0xFF) { - resultPtr[8] = (byte)((byte)(hi << 4) | lo); + resultPtr[8] = (byte) ((byte) (hi << 4) | lo); // 9 byte if (value[21] < MaximalChar && (hi = TableFromHexToBytes[value[21]]) != 0xFF && value[22] < MaximalChar && (lo = TableFromHexToBytes[value[22]]) != 0xFF) { - resultPtr[9] = (byte)((byte)(hi << 4) | lo); + resultPtr[9] = (byte) ((byte) (hi << 4) | lo); // value[23] == '-' @@ -2285,42 +2285,42 @@ private static bool TryParsePtrD(char* value, byte* resultPtr) && value[25] < MaximalChar && (lo = TableFromHexToBytes[value[25]]) != 0xFF) { - resultPtr[10] = (byte)((byte)(hi << 4) | lo); + resultPtr[10] = (byte) ((byte) (hi << 4) | lo); // 11 byte if (value[26] < MaximalChar && (hi = TableFromHexToBytes[value[26]]) != 0xFF && value[27] < MaximalChar && (lo = TableFromHexToBytes[value[27]]) != 0xFF) { - resultPtr[11] = (byte)((byte)(hi << 4) | lo); + resultPtr[11] = (byte) ((byte) (hi << 4) | lo); // 12 byte if (value[28] < MaximalChar && (hi = TableFromHexToBytes[value[28]]) != 0xFF && value[29] < MaximalChar && (lo = TableFromHexToBytes[value[29]]) != 0xFF) { - resultPtr[12] = (byte)((byte)(hi << 4) | lo); + resultPtr[12] = (byte) ((byte) (hi << 4) | lo); // 13 byte if (value[30] < MaximalChar && (hi = TableFromHexToBytes[value[30]]) != 0xFF && value[31] < MaximalChar && (lo = TableFromHexToBytes[value[31]]) != 0xFF) { - resultPtr[13] = (byte)((byte)(hi << 4) | lo); + resultPtr[13] = (byte) ((byte) (hi << 4) | lo); // 14 byte if (value[32] < MaximalChar && (hi = TableFromHexToBytes[value[32]]) != 0xFF && value[33] < MaximalChar && (lo = TableFromHexToBytes[value[33]]) != 0xFF) { - resultPtr[14] = (byte)((byte)(hi << 4) | lo); + resultPtr[14] = (byte) ((byte) (hi << 4) | lo); // 15 byte if (value[34] < MaximalChar && (hi = TableFromHexToBytes[value[34]]) != 0xFF && value[35] < MaximalChar && (lo = TableFromHexToBytes[value[35]]) != 0xFF) { - resultPtr[15] = (byte)((byte)(hi << 4) | lo); + resultPtr[15] = (byte) ((byte) (hi << 4) | lo); return true; } } @@ -2358,28 +2358,28 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) && value[4] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[4]]) != 0xFF) { - resultPtr[0] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[0] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 1 byte if (value[5] < MaximalChar && (hexByteHi = TableFromHexToBytes[value[5]]) != 0xFF && value[6] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[6]]) != 0xFF) { - resultPtr[1] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[1] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 2 byte if (value[7] < MaximalChar && (hexByteHi = TableFromHexToBytes[value[7]]) != 0xFF && value[8] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[8]]) != 0xFF) { - resultPtr[2] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[2] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 3 byte if (value[9] < MaximalChar && (hexByteHi = TableFromHexToBytes[value[9]]) != 0xFF && value[10] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[10]]) != 0xFF) { - resultPtr[3] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[3] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[11] == ',' // value[12] == '0' @@ -2391,14 +2391,14 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) && value[15] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[15]]) != 0xFF) { - resultPtr[4] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[4] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 5 byte if (value[16] < MaximalChar && (hexByteHi = TableFromHexToBytes[value[16]]) != 0xFF && value[17] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[17]]) != 0xFF) { - resultPtr[5] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[5] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[18] == ',' // value[19] == '0' @@ -2410,14 +2410,14 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) && value[22] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[22]]) != 0xFF) { - resultPtr[6] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[6] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 7 byte if (value[23] < MaximalChar && (hexByteHi = TableFromHexToBytes[value[23]]) != 0xFF && value[24] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[24]]) != 0xFF) { - resultPtr[7] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[7] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[25] == ',' // value[26] == '{' @@ -2430,7 +2430,7 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) && value[30] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[30]]) != 0xFF) { - resultPtr[8] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[8] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[31] == ',' // value[32] == '0' @@ -2442,7 +2442,7 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) && value[35] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[35]]) != 0xFF) { - resultPtr[9] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[9] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[36] == ',' // value[37] == '0' @@ -2454,7 +2454,7 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) && value[40] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[40]]) != 0xFF) { - resultPtr[10] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[10] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[41] == ',' // value[42] == '0' @@ -2466,7 +2466,7 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) && value[45] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[45]]) != 0xFF) { - resultPtr[11] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[11] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[46] == ',' // value[47] == '0' @@ -2478,7 +2478,7 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) && value[50] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[50]]) != 0xFF) { - resultPtr[12] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[12] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[51] == ',' // value[52] == '0' @@ -2490,7 +2490,7 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) && value[55] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[55]]) != 0xFF) { - resultPtr[13] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[13] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[56] == ',' // value[57] == '0' @@ -2502,7 +2502,7 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) && value[60] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[60]]) != 0xFF) { - resultPtr[14] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[14] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[61] == ',' // value[62] == '0' @@ -2514,7 +2514,7 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) && value[65] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[65]]) != 0xFF) { - resultPtr[15] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[15] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); return true; } } @@ -2548,112 +2548,112 @@ private static bool TryParsePtrNUtf8(byte* value, byte* resultPtr) && value[1] < MaximalChar && (lo = TableFromHexToBytes[value[1]]) != 0xFF) { - resultPtr[0] = (byte)((byte)(hi << 4) | lo); + resultPtr[0] = (byte) ((byte) (hi << 4) | lo); // 1 byte if (value[2] < MaximalChar && (hi = TableFromHexToBytes[value[2]]) != 0xFF && value[3] < MaximalChar && (lo = TableFromHexToBytes[value[3]]) != 0xFF) { - resultPtr[1] = (byte)((byte)(hi << 4) | lo); + resultPtr[1] = (byte) ((byte) (hi << 4) | lo); // 2 byte if (value[4] < MaximalChar && (hi = TableFromHexToBytes[value[4]]) != 0xFF && value[5] < MaximalChar && (lo = TableFromHexToBytes[value[5]]) != 0xFF) { - resultPtr[2] = (byte)((byte)(hi << 4) | lo); + resultPtr[2] = (byte) ((byte) (hi << 4) | lo); // 3 byte if (value[6] < MaximalChar && (hi = TableFromHexToBytes[value[6]]) != 0xFF && value[7] < MaximalChar && (lo = TableFromHexToBytes[value[7]]) != 0xFF) { - resultPtr[3] = (byte)((byte)(hi << 4) | lo); + resultPtr[3] = (byte) ((byte) (hi << 4) | lo); // 4 byte if (value[8] < MaximalChar && (hi = TableFromHexToBytes[value[8]]) != 0xFF && value[9] < MaximalChar && (lo = TableFromHexToBytes[value[9]]) != 0xFF) { - resultPtr[4] = (byte)((byte)(hi << 4) | lo); + resultPtr[4] = (byte) ((byte) (hi << 4) | lo); // 5 byte if (value[10] < MaximalChar && (hi = TableFromHexToBytes[value[10]]) != 0xFF && value[11] < MaximalChar && (lo = TableFromHexToBytes[value[11]]) != 0xFF) { - resultPtr[5] = (byte)((byte)(hi << 4) | lo); + resultPtr[5] = (byte) ((byte) (hi << 4) | lo); // 6 byte if (value[12] < MaximalChar && (hi = TableFromHexToBytes[value[12]]) != 0xFF && value[13] < MaximalChar && (lo = TableFromHexToBytes[value[13]]) != 0xFF) { - resultPtr[6] = (byte)((byte)(hi << 4) | lo); + resultPtr[6] = (byte) ((byte) (hi << 4) | lo); // 7 byte if (value[14] < MaximalChar && (hi = TableFromHexToBytes[value[14]]) != 0xFF && value[15] < MaximalChar && (lo = TableFromHexToBytes[value[15]]) != 0xFF) { - resultPtr[7] = (byte)((byte)(hi << 4) | lo); + resultPtr[7] = (byte) ((byte) (hi << 4) | lo); // 8 byte if (value[16] < MaximalChar && (hi = TableFromHexToBytes[value[16]]) != 0xFF && value[17] < MaximalChar && (lo = TableFromHexToBytes[value[17]]) != 0xFF) { - resultPtr[8] = (byte)((byte)(hi << 4) | lo); + resultPtr[8] = (byte) ((byte) (hi << 4) | lo); // 9 byte if (value[18] < MaximalChar && (hi = TableFromHexToBytes[value[18]]) != 0xFF && value[19] < MaximalChar && (lo = TableFromHexToBytes[value[19]]) != 0xFF) { - resultPtr[9] = (byte)((byte)(hi << 4) | lo); + resultPtr[9] = (byte) ((byte) (hi << 4) | lo); // 10 byte if (value[20] < MaximalChar && (hi = TableFromHexToBytes[value[20]]) != 0xFF && value[21] < MaximalChar && (lo = TableFromHexToBytes[value[21]]) != 0xFF) { - resultPtr[10] = (byte)((byte)(hi << 4) | lo); + resultPtr[10] = (byte) ((byte) (hi << 4) | lo); // 11 byte if (value[22] < MaximalChar && (hi = TableFromHexToBytes[value[22]]) != 0xFF && value[23] < MaximalChar && (lo = TableFromHexToBytes[value[23]]) != 0xFF) { - resultPtr[11] = (byte)((byte)(hi << 4) | lo); + resultPtr[11] = (byte) ((byte) (hi << 4) | lo); // 12 byte if (value[24] < MaximalChar && (hi = TableFromHexToBytes[value[24]]) != 0xFF && value[25] < MaximalChar && (lo = TableFromHexToBytes[value[25]]) != 0xFF) { - resultPtr[12] = (byte)((byte)(hi << 4) | lo); + resultPtr[12] = (byte) ((byte) (hi << 4) | lo); // 13 byte if (value[26] < MaximalChar && (hi = TableFromHexToBytes[value[26]]) != 0xFF && value[27] < MaximalChar && (lo = TableFromHexToBytes[value[27]]) != 0xFF) { - resultPtr[13] = (byte)((byte)(hi << 4) | lo); + resultPtr[13] = (byte) ((byte) (hi << 4) | lo); // 14 byte if (value[28] < MaximalChar && (hi = TableFromHexToBytes[value[28]]) != 0xFF && value[29] < MaximalChar && (lo = TableFromHexToBytes[value[29]]) != 0xFF) { - resultPtr[14] = (byte)((byte)(hi << 4) | lo); + resultPtr[14] = (byte) ((byte) (hi << 4) | lo); // 15 byte if (value[30] < MaximalChar && (hi = TableFromHexToBytes[value[30]]) != 0xFF && value[31] < MaximalChar && (lo = TableFromHexToBytes[value[31]]) != 0xFF) { - resultPtr[15] = (byte)((byte)(hi << 4) | lo); + resultPtr[15] = (byte) ((byte) (hi << 4) | lo); return true; } } @@ -2687,28 +2687,28 @@ private static bool TryParsePtrDUtf8(byte* value, byte* resultPtr) && value[1] < MaximalChar && (lo = TableFromHexToBytes[value[1]]) != 0xFF) { - resultPtr[0] = (byte)((byte)(hi << 4) | lo); + resultPtr[0] = (byte) ((byte) (hi << 4) | lo); // 1 byte if (value[2] < MaximalChar && (hi = TableFromHexToBytes[value[2]]) != 0xFF && value[3] < MaximalChar && (lo = TableFromHexToBytes[value[3]]) != 0xFF) { - resultPtr[1] = (byte)((byte)(hi << 4) | lo); + resultPtr[1] = (byte) ((byte) (hi << 4) | lo); // 2 byte if (value[4] < MaximalChar && (hi = TableFromHexToBytes[value[4]]) != 0xFF && value[5] < MaximalChar && (lo = TableFromHexToBytes[value[5]]) != 0xFF) { - resultPtr[2] = (byte)((byte)(hi << 4) | lo); + resultPtr[2] = (byte) ((byte) (hi << 4) | lo); // 3 byte if (value[6] < MaximalChar && (hi = TableFromHexToBytes[value[6]]) != 0xFF && value[7] < MaximalChar && (lo = TableFromHexToBytes[value[7]]) != 0xFF) { - resultPtr[3] = (byte)((byte)(hi << 4) | lo); + resultPtr[3] = (byte) ((byte) (hi << 4) | lo); // value[8] == '-' @@ -2718,14 +2718,14 @@ private static bool TryParsePtrDUtf8(byte* value, byte* resultPtr) && value[10] < MaximalChar && (lo = TableFromHexToBytes[value[10]]) != 0xFF) { - resultPtr[4] = (byte)((byte)(hi << 4) | lo); + resultPtr[4] = (byte) ((byte) (hi << 4) | lo); // 5 byte if (value[11] < MaximalChar && (hi = TableFromHexToBytes[value[11]]) != 0xFF && value[12] < MaximalChar && (lo = TableFromHexToBytes[value[12]]) != 0xFF) { - resultPtr[5] = (byte)((byte)(hi << 4) | lo); + resultPtr[5] = (byte) ((byte) (hi << 4) | lo); // value[13] == '-' @@ -2735,14 +2735,14 @@ private static bool TryParsePtrDUtf8(byte* value, byte* resultPtr) && value[15] < MaximalChar && (lo = TableFromHexToBytes[value[15]]) != 0xFF) { - resultPtr[6] = (byte)((byte)(hi << 4) | lo); + resultPtr[6] = (byte) ((byte) (hi << 4) | lo); // 7 byte if (value[16] < MaximalChar && (hi = TableFromHexToBytes[value[16]]) != 0xFF && value[17] < MaximalChar && (lo = TableFromHexToBytes[value[17]]) != 0xFF) { - resultPtr[7] = (byte)((byte)(hi << 4) | lo); + resultPtr[7] = (byte) ((byte) (hi << 4) | lo); // value[18] == '-' @@ -2752,14 +2752,14 @@ private static bool TryParsePtrDUtf8(byte* value, byte* resultPtr) && value[20] < MaximalChar && (lo = TableFromHexToBytes[value[20]]) != 0xFF) { - resultPtr[8] = (byte)((byte)(hi << 4) | lo); + resultPtr[8] = (byte) ((byte) (hi << 4) | lo); // 9 byte if (value[21] < MaximalChar && (hi = TableFromHexToBytes[value[21]]) != 0xFF && value[22] < MaximalChar && (lo = TableFromHexToBytes[value[22]]) != 0xFF) { - resultPtr[9] = (byte)((byte)(hi << 4) | lo); + resultPtr[9] = (byte) ((byte) (hi << 4) | lo); // value[23] == '-' @@ -2769,42 +2769,42 @@ private static bool TryParsePtrDUtf8(byte* value, byte* resultPtr) && value[25] < MaximalChar && (lo = TableFromHexToBytes[value[25]]) != 0xFF) { - resultPtr[10] = (byte)((byte)(hi << 4) | lo); + resultPtr[10] = (byte) ((byte) (hi << 4) | lo); // 11 byte if (value[26] < MaximalChar && (hi = TableFromHexToBytes[value[26]]) != 0xFF && value[27] < MaximalChar && (lo = TableFromHexToBytes[value[27]]) != 0xFF) { - resultPtr[11] = (byte)((byte)(hi << 4) | lo); + resultPtr[11] = (byte) ((byte) (hi << 4) | lo); // 12 byte if (value[28] < MaximalChar && (hi = TableFromHexToBytes[value[28]]) != 0xFF && value[29] < MaximalChar && (lo = TableFromHexToBytes[value[29]]) != 0xFF) { - resultPtr[12] = (byte)((byte)(hi << 4) | lo); + resultPtr[12] = (byte) ((byte) (hi << 4) | lo); // 13 byte if (value[30] < MaximalChar && (hi = TableFromHexToBytes[value[30]]) != 0xFF && value[31] < MaximalChar && (lo = TableFromHexToBytes[value[31]]) != 0xFF) { - resultPtr[13] = (byte)((byte)(hi << 4) | lo); + resultPtr[13] = (byte) ((byte) (hi << 4) | lo); // 14 byte if (value[32] < MaximalChar && (hi = TableFromHexToBytes[value[32]]) != 0xFF && value[33] < MaximalChar && (lo = TableFromHexToBytes[value[33]]) != 0xFF) { - resultPtr[14] = (byte)((byte)(hi << 4) | lo); + resultPtr[14] = (byte) ((byte) (hi << 4) | lo); // 15 byte if (value[34] < MaximalChar && (hi = TableFromHexToBytes[value[34]]) != 0xFF && value[35] < MaximalChar && (lo = TableFromHexToBytes[value[35]]) != 0xFF) { - resultPtr[15] = (byte)((byte)(hi << 4) | lo); + resultPtr[15] = (byte) ((byte) (hi << 4) | lo); return true; } } @@ -2842,28 +2842,28 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) && value[4] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[4]]) != 0xFF) { - resultPtr[0] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[0] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 1 byte if (value[5] < MaximalChar && (hexByteHi = TableFromHexToBytes[value[5]]) != 0xFF && value[6] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[6]]) != 0xFF) { - resultPtr[1] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[1] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 2 byte if (value[7] < MaximalChar && (hexByteHi = TableFromHexToBytes[value[7]]) != 0xFF && value[8] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[8]]) != 0xFF) { - resultPtr[2] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[2] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 3 byte if (value[9] < MaximalChar && (hexByteHi = TableFromHexToBytes[value[9]]) != 0xFF && value[10] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[10]]) != 0xFF) { - resultPtr[3] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[3] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[11] == ',' // value[12] == '0' @@ -2875,14 +2875,14 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) && value[15] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[15]]) != 0xFF) { - resultPtr[4] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[4] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 5 byte if (value[16] < MaximalChar && (hexByteHi = TableFromHexToBytes[value[16]]) != 0xFF && value[17] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[17]]) != 0xFF) { - resultPtr[5] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[5] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[18] == ',' // value[19] == '0' @@ -2894,14 +2894,14 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) && value[22] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[22]]) != 0xFF) { - resultPtr[6] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[6] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 7 byte if (value[23] < MaximalChar && (hexByteHi = TableFromHexToBytes[value[23]]) != 0xFF && value[24] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[24]]) != 0xFF) { - resultPtr[7] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[7] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[25] == ',' // value[26] == '{' @@ -2914,7 +2914,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) && value[30] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[30]]) != 0xFF) { - resultPtr[8] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[8] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[31] == ',' // value[32] == '0' @@ -2926,7 +2926,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) && value[35] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[35]]) != 0xFF) { - resultPtr[9] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[9] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[36] == ',' // value[37] == '0' @@ -2938,7 +2938,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) && value[40] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[40]]) != 0xFF) { - resultPtr[10] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[10] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[41] == ',' // value[42] == '0' @@ -2950,7 +2950,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) && value[45] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[45]]) != 0xFF) { - resultPtr[11] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[11] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[46] == ',' // value[47] == '0' @@ -2962,7 +2962,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) && value[50] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[50]]) != 0xFF) { - resultPtr[12] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[12] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[51] == ',' // value[52] == '0' @@ -2974,7 +2974,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) && value[55] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[55]]) != 0xFF) { - resultPtr[13] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[13] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[56] == ',' // value[57] == '0' @@ -2986,7 +2986,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) && value[60] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[60]]) != 0xFF) { - resultPtr[14] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[14] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // value[61] == ',' // value[62] == '0' @@ -2998,7 +2998,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) && value[65] < MaximalChar && (hexByteLow = TableFromHexToBytes[value[65]]) != 0xFF) { - resultPtr[15] = (byte)((byte)(hexByteHi << 4) | hexByteLow); + resultPtr[15] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); return true; } } @@ -3023,7 +3023,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // // IComparisonOperators // -#if !NET6_0 +#if NET7_0_OR_GREATER /// #else /// @@ -3118,7 +3118,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) return false; } -#if !NET6_0 +#if NET7_0_OR_GREATER /// #else /// @@ -3216,7 +3216,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) return true; } -#if !NET6_0 +#if NET7_0_OR_GREATER /// #else /// @@ -3314,7 +3314,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) return false; } -#if !NET6_0 +#if NET7_0_OR_GREATER /// #else /// @@ -3415,7 +3415,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // // IParsable // -#if !NET6_0 +#if NET7_0_OR_GREATER /// #else /// @@ -3431,7 +3431,7 @@ public static Uuid Parse(string s, IFormatProvider? provider) return Parse(s); } -#if !NET6_0 +#if NET7_0_OR_GREATER /// #else /// @@ -3450,7 +3450,7 @@ public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? prov // // ISpanParsable // -#if !NET6_0 +#if NET7_0_OR_GREATER /// #else /// @@ -3465,7 +3465,7 @@ public static Uuid Parse(ReadOnlySpan s, IFormatProvider? provider) return Parse(s); } -#if !NET6_0 +#if NET7_0_OR_GREATER /// #else /// @@ -3498,20 +3498,20 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out public static Uuid NewTimeBased() { byte* resultPtr = stackalloc byte[16]; - var resultAsGuidPtr = (Guid*)resultPtr; + var resultAsGuidPtr = (Guid*) resultPtr; var guid = Guid.NewGuid(); resultAsGuidPtr[0] = guid; long currentTicks = DateTime.UtcNow.Ticks - ChristianCalendarGregorianReformTicksDate; - var ticksPtr = (byte*)¤tTicks; + var ticksPtr = (byte*) ¤tTicks; resultPtr[0] = ticksPtr[3]; resultPtr[1] = ticksPtr[2]; resultPtr[2] = ticksPtr[1]; resultPtr[3] = ticksPtr[0]; resultPtr[4] = ticksPtr[5]; resultPtr[5] = ticksPtr[4]; - resultPtr[6] = (byte)((ticksPtr[7] & ResetVersionMask) | Version1Flag); + resultPtr[6] = (byte) ((ticksPtr[7] & ResetVersionMask) | Version1Flag); resultPtr[7] = ticksPtr[6]; - resultPtr[8] = (byte)((resultPtr[8] & ResetReservedMask) | ReservedFlag); + resultPtr[8] = (byte) ((resultPtr[8] & ResetReservedMask) | ReservedFlag); return new Uuid(resultPtr); } @@ -3522,12 +3522,12 @@ public static Uuid NewTimeBased() public static Uuid NewMySqlOptimized() { byte* resultPtr = stackalloc byte[16]; - var resultAsGuidPtr = (Guid*)resultPtr; + var resultAsGuidPtr = (Guid*) resultPtr; var guid = Guid.NewGuid(); resultAsGuidPtr[0] = guid; long currentTicks = DateTime.UtcNow.Ticks - ChristianCalendarGregorianReformTicksDate; - var ticksPtr = (byte*)¤tTicks; - resultPtr[0] = (byte)((ticksPtr[7] & ResetVersionMask) | Version1Flag); + var ticksPtr = (byte*) ¤tTicks; + resultPtr[0] = (byte) ((ticksPtr[7] & ResetVersionMask) | Version1Flag); resultPtr[1] = ticksPtr[6]; resultPtr[2] = ticksPtr[5]; resultPtr[3] = ticksPtr[4]; @@ -3535,7 +3535,7 @@ public static Uuid NewMySqlOptimized() resultPtr[5] = ticksPtr[2]; resultPtr[6] = ticksPtr[1]; resultPtr[7] = ticksPtr[0]; - resultPtr[8] = (byte)((resultPtr[8] & ResetReservedMask) | ReservedFlag); + resultPtr[8] = (byte) ((resultPtr[8] & ResetReservedMask) | ReservedFlag); return new Uuid(resultPtr); } diff --git a/tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj b/tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj index 82d713d..fa69252 100644 --- a/tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj +++ b/tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj @@ -10,7 +10,7 @@ - +