From f8541fd239d602067c1c96b9b41fca07addb14c1 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 15 Jul 2020 14:31:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Code=20style=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 270 ++++++++++++++++-------------- X10D.ruleset | 259 ---------------------------- X10D/src/BooleanExtensions.cs | 74 ++++---- X10D/src/ByteExtensions.cs | 96 +++++------ X10D/src/CharExtensions.cs | 32 ++-- X10D/src/ComparableExtensions.cs | 10 +- X10D/src/ConvertibleExtensions.cs | 88 +++++----- X10D/src/DateTimeExtensions.cs | 76 +++++---- X10D/src/DictionaryExtensions.cs | 28 ++-- X10D/src/DoubleExtensions.cs | 46 ++--- X10D/src/EndPointExtensions.cs | 18 +- X10D/src/EnumerableExtensions.cs | 14 +- X10D/src/Int16Extensions.cs | 108 +++++++----- X10D/src/Int32Extensions.cs | 100 ++++++----- X10D/src/Int64Extensions.cs | 110 +++++++----- X10D/src/ListExtensions.cs | 42 ++--- X10D/src/RandomExtensions.cs | 38 +++-- X10D/src/ReflectionExtensions.cs | 58 ++++--- X10D/src/SingleExtensions.cs | 44 ++--- X10D/src/StreamExtensions.cs | 13 +- X10D/src/StringExtensions.cs | 154 +++++++++-------- X10D/src/StructExtensions.cs | 30 ++-- X10D/src/TimeSpanParser.cs | 12 +- 23 files changed, 813 insertions(+), 907 deletions(-) delete mode 100644 X10D.ruleset diff --git a/.editorconfig b/.editorconfig index 8b0f5bc..ae973bf 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,195 +1,215 @@ +# All files +[*] +guidelines = 130 + # C# files [*.cs] #### Core EditorConfig Options #### # Indentation and spacing -indent_size = 4 -indent_style = space -tab_width = 4 +indent_size=4 +indent_style=space +tab_width=4 # New line preferences -end_of_line = crlf -insert_final_newline = true +end_of_line=crlf +insert_final_newline=true #### .NET Coding Conventions #### # Organize usings -dotnet_separate_import_directive_groups = false -dotnet_sort_system_directives_first = true +dotnet_separate_import_directive_groups=false +dotnet_sort_system_directives_first=true # this. and Me. preferences -dotnet_style_qualification_for_event = true:suggestion -dotnet_style_qualification_for_field = true:suggestion -dotnet_style_qualification_for_method = true:suggestion -dotnet_style_qualification_for_property = true:suggestion +dotnet_style_qualification_for_event=true:suggestion +dotnet_style_qualification_for_field=true:suggestion +dotnet_style_qualification_for_method=true:suggestion +dotnet_style_qualification_for_property=true:suggestion # Language keywords vs BCL types preferences -dotnet_style_predefined_type_for_locals_parameters_members = true:warning -dotnet_style_predefined_type_for_member_access = true:warning +dotnet_style_predefined_type_for_locals_parameters_members=true:warning +dotnet_style_predefined_type_for_member_access=true:warning # 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 +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 +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_prefer_auto_properties = true:silent -dotnet_style_prefer_compound_assignment = true:suggestion -dotnet_style_prefer_conditional_expression_over_assignment = true:silent -dotnet_style_prefer_conditional_expression_over_return = true:silent -dotnet_style_prefer_inferred_anonymous_type_member_names = false:suggestion -dotnet_style_prefer_inferred_tuple_names = false:suggestion -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion -dotnet_style_prefer_simplified_interpolation = true:suggestion +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_prefer_auto_properties=true:silent +dotnet_style_prefer_compound_assignment=true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment=true:silent +dotnet_style_prefer_conditional_expression_over_return=true:silent +dotnet_style_prefer_inferred_anonymous_type_member_names=false:suggestion +dotnet_style_prefer_inferred_tuple_names=false:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method=true:suggestion +dotnet_style_prefer_simplified_interpolation=true:suggestion # Field preferences -dotnet_style_readonly_field = true:suggestion +dotnet_style_readonly_field=true:suggestion # Parameter preferences -dotnet_code_quality_unused_parameters = all:suggestion +dotnet_code_quality_unused_parameters=all:suggestion #### C# Coding Conventions #### # var preferences -csharp_style_var_elsewhere = false:warning -csharp_style_var_for_built_in_types = true:warning -csharp_style_var_when_type_is_apparent = true:warning +csharp_style_var_elsewhere=true:warning +csharp_style_var_when_type_is_apparent=true:warning +csharp_style_var_for_built_in_types=true:warning # Expression-bodied members -csharp_style_expression_bodied_accessors = true:suggestion -csharp_style_expression_bodied_constructors = false:suggestion -csharp_style_expression_bodied_indexers = true:suggestion -csharp_style_expression_bodied_lambdas = true:silent -csharp_style_expression_bodied_local_functions = false:silent -csharp_style_expression_bodied_methods = false:suggestion -csharp_style_expression_bodied_operators = true:suggestion -csharp_style_expression_bodied_properties = false:suggestion +csharp_style_expression_bodied_accessors=true:suggestion +csharp_style_expression_bodied_constructors=false:suggestion +csharp_style_expression_bodied_indexers=true:suggestion +csharp_style_expression_bodied_lambdas=true:silent +csharp_style_expression_bodied_local_functions=false:silent +csharp_style_expression_bodied_methods=false:suggestion +csharp_style_expression_bodied_operators=false:suggestion +csharp_style_expression_bodied_properties=false:suggestion # 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_switch_expression = true:suggestion +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_switch_expression=true:suggestion # Null-checking preferences -csharp_style_conditional_delegate_call = true:suggestion +csharp_style_conditional_delegate_call=true:suggestion # Modifier preferences -csharp_prefer_static_local_function = true:suggestion -csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent +csharp_prefer_static_local_function=true:suggestion +csharp_preferred_modifier_order=public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent # Code-block preferences -csharp_prefer_braces = true:suggestion -csharp_prefer_simple_using_statement = true:suggestion +csharp_prefer_braces=true:suggestion +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 +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 = inside_namespace:suggestion +csharp_using_directive_placement=inside_namespace:suggestion #### C# Formatting Rules #### +max_line_length=130 + # 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 +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 +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 = false -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 +csharp_space_after_cast=false +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 +csharp_preserve_single_line_blocks=true +csharp_preserve_single_line_statements=true #### Naming styles #### # Naming rules -dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion -dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface -dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i +dotnet_naming_rule.interface_should_be_begins_with_i.severity=suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols=interface +dotnet_naming_rule.interface_should_be_begins_with_i.style=begins_with_i -dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.types_should_be_pascal_case.symbols = types -dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case +dotnet_naming_rule.types_should_be_pascal_case.severity=suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols=types +dotnet_naming_rule.types_should_be_pascal_case.style=pascal_case -dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members -dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity=suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols=non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style=pascal_case # Symbol specifications -dotnet_naming_symbols.interface.applicable_kinds = interface -dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.interface.required_modifiers = +dotnet_naming_symbols.interface.applicable_kinds=interface +dotnet_naming_symbols.interface.applicable_accessibilities=public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers= -dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum -dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.types.required_modifiers = +dotnet_naming_symbols.types.applicable_kinds=class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities=public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers= -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.non_field_members.required_modifiers = +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.non_field_members.required_modifiers= # Naming styles -dotnet_naming_style.pascal_case.required_prefix = -dotnet_naming_style.pascal_case.required_suffix = -dotnet_naming_style.pascal_case.word_separator = -dotnet_naming_style.pascal_case.capitalization = pascal_case +dotnet_naming_style.pascal_case.required_prefix= + dotnet_naming_style.pascal_case.required_suffix= + dotnet_naming_style.pascal_case.word_separator= + dotnet_naming_style.pascal_case.capitalization=pascal_case -dotnet_naming_style.begins_with_i.required_prefix = I -dotnet_naming_style.begins_with_i.required_suffix = -dotnet_naming_style.begins_with_i.word_separator = -dotnet_naming_style.begins_with_i.capitalization = pascal_case +dotnet_naming_style.begins_with_i.required_prefix=I +dotnet_naming_style.begins_with_i.required_suffix= +dotnet_naming_style.begins_with_i.word_separator= + dotnet_naming_style.begins_with_i.capitalization=pascal_case + +# XML comment analysis is disabled due to project configuration +# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA0001.md +dotnet_diagnostic.SA0001.severity = silent + +# A C# code file is missing a standard file header. +# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md +dotnet_diagnostic.SA1633.severity = silent + +# Consider calling ConfigureAwait on the awaited Task +# https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2007?view=vs-2019 +# https://github.com/JosefPihrt/Roslynator/blob/master/docs/analyzers/RCS1090.md +dotnet_diagnostic.CA2007.severity = silent +dotnet_diagnostic.RCS1090.severity = silent diff --git a/X10D.ruleset b/X10D.ruleset deleted file mode 100644 index 9c39803..0000000 --- a/X10D.ruleset +++ /dev/null @@ -1,259 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/X10D/src/BooleanExtensions.cs b/X10D/src/BooleanExtensions.cs index b16ba83..fbdab76 100644 --- a/X10D/src/BooleanExtensions.cs +++ b/X10D/src/BooleanExtensions.cs @@ -1,128 +1,142 @@ namespace X10D { /// - /// Extension methods for . + /// Extension methods for . /// public static class BooleanExtensions { /// - /// Performs logical AND on this and another . + /// Performs logical AND on this and another . /// /// The boolean. /// The boolean comparator. - /// Returns if AND - /// evaluate to , or otherwise. + /// + /// Returns if AND + /// evaluate to , or otherwise. + /// public static bool And(this bool value, bool comparison) { return value && comparison; } /// - /// Performs logical NAND on this and another . + /// Performs logical NAND on this and another . /// /// The boolean. /// The boolean comparator. - /// Returns if NAND - /// evaluate to , or otherwise. + /// + /// Returns if NAND + /// evaluate to , or otherwise. + /// public static bool NAnd(this bool value, bool comparison) { return !(value && comparison); } /// - /// Performs logical NOR on this and another . + /// Performs logical NOR on this and another . /// /// The boolean. /// The boolean comparator. - /// Returns if NOR - /// evaluate to , or otherwise. + /// + /// Returns if NOR + /// evaluate to , or otherwise. + /// public static bool NOr(this bool value, bool comparison) { return !(value || comparison); } /// - /// Performs logical NOT on this . + /// Performs logical NOT on this . /// /// The boolean. - /// Returns if is , - /// or otherwise. + /// + /// Returns if is , + /// or otherwise. + /// public static bool Not(this bool value) { return !value; } /// - /// Performs logical OR on this and another . + /// Performs logical OR on this and another . /// /// The boolean. /// The boolean comparator. - /// Returns if OR - /// evaluate to , or otherwise. + /// + /// Returns if OR + /// evaluate to , or otherwise. + /// public static bool Or(this bool value, bool comparison) { return value || comparison; } /// - /// Gets the value of this boolean as represented by . + /// Gets the value of this boolean as represented by . /// /// The boolean. - /// Returns 1 if is , or 0 otherwise. + /// Returns 1 if is , or 0 otherwise. public static byte ToByte(this bool value) { return (byte)value.ToInt32(); } /// - /// Gets the value of this boolean as represented by . + /// Gets the value of this boolean as represented by . /// /// The boolean. - /// Returns 1 if is , or 0 otherwise. + /// Returns 1 if is , or 0 otherwise. public static short ToInt16(this bool value) { return (short)value.ToInt32(); } /// - /// Gets the value of this boolean as represented by . + /// Gets the value of this boolean as represented by . /// /// The boolean. - /// Returns 1 if is , or 0 otherwise. + /// Returns 1 if is , or 0 otherwise. public static int ToInt32(this bool value) { return value ? 1 : 0; } /// - /// Gets the value of this boolean as represented by . + /// Gets the value of this boolean as represented by . /// /// The boolean. - /// Returns 1 if is , 0 otherwise. + /// Returns 1 if is , 0 otherwise. public static long ToInt64(this bool value) { return value.ToInt32(); } /// - /// Performs logical XNOR on this and another . + /// Performs logical XNOR on this and another . /// /// The boolean. /// The boolean comparator. - /// Returns if XNOR - /// evaluate to , or otherwise. + /// + /// Returns if XNOR + /// evaluate to , or otherwise. + /// public static bool XNOr(this bool value, bool comparison) { return !(value ^ comparison); } /// - /// Performs logical XOR on this and another . + /// Performs logical XOR on this and another . /// /// The boolean. /// The boolean comparator. - /// Returns if XOR - /// evaluate to , or otherwise. + /// + /// Returns if XOR + /// evaluate to , or otherwise. + /// public static bool XOr(this bool value, bool comparison) { return value ^ comparison; diff --git a/X10D/src/ByteExtensions.cs b/X10D/src/ByteExtensions.cs index e84264d..dd1f634 100644 --- a/X10D/src/ByteExtensions.cs +++ b/X10D/src/ByteExtensions.cs @@ -6,101 +6,68 @@ using System.Text; /// - /// Extension methods for . + /// Extension methods for . /// public static class ByteExtensions { /// - /// Gets a literally representing the raw values in the []. + /// Gets a literally representing the raw values in the []. /// /// The bytes to get. - /// Returns a . + /// Returns a . public static string AsString(this IEnumerable bytes) { return BitConverter.ToString(bytes.ToArray()); } /// - /// Converts the [] to an . + /// Converts the [] to an . /// /// The bytes to convert. - /// Returns an . + /// Returns an . public static short GetInt16(this IEnumerable bytes) { return BitConverter.ToInt16(bytes.ToArray(), 0); } /// - /// Converts the [] to an . + /// Converts the [] to an . /// /// The bytes to convert. - /// Returns an . + /// Returns an . public static int GetInt32(this IEnumerable bytes) { return BitConverter.ToInt32(bytes.ToArray(), 0); } /// - /// Converts the [] to an . + /// Converts the [] to an . /// /// The bytes to convert. - /// Returns an . + /// Returns an . public static long GetInt64(this IEnumerable bytes) { return BitConverter.ToInt64(bytes.ToArray(), 0); } /// - /// Converts the [] to a . + /// Gets a representing the value the [] with + /// encoding. /// /// The bytes to convert. - /// Returns an . - [CLSCompliant(false)] - public static ushort GetUInt16(this IEnumerable bytes) - { - return BitConverter.ToUInt16(bytes.ToArray(), 0); - } - - /// - /// Converts the [] to an . - /// - /// The bytes to convert. - /// Returns an . - [CLSCompliant(false)] - public static uint GetUInt32(this IEnumerable bytes) - { - return BitConverter.ToUInt32(bytes.ToArray(), 0); - } - - /// - /// Converts the [] to an . - /// - /// The bytes to convert. - /// Returns an . - [CLSCompliant(false)] - public static ulong GetUInt64(this IEnumerable bytes) - { - return BitConverter.ToUInt64(bytes.ToArray(), 0); - } - - /// - /// Gets a representing the value the [] with - /// encoding. - /// - /// The bytes to convert. - /// Returns a . + /// Returns a . public static string GetString(this IEnumerable bytes) { return bytes.GetString(Encoding.UTF8); } /// - /// Gets a representing the value the [] with the provided encoding. + /// Gets a representing the value the [] with the provided encoding. /// /// The bytes to convert. /// The encoding to use. - /// Returns a . - /// is . + /// Returns a . + /// is . public static string GetString(this IEnumerable bytes, Encoding encoding) { if (encoding is null) @@ -112,5 +79,38 @@ var array = bytes.ToArray(); return encoding.GetString(array, 0, array.Length); } + + /// + /// Converts the [] to a . + /// + /// The bytes to convert. + /// Returns an . + [CLSCompliant(false)] + public static ushort GetUInt16(this IEnumerable bytes) + { + return BitConverter.ToUInt16(bytes.ToArray(), 0); + } + + /// + /// Converts the [] to an . + /// + /// The bytes to convert. + /// Returns an . + [CLSCompliant(false)] + public static uint GetUInt32(this IEnumerable bytes) + { + return BitConverter.ToUInt32(bytes.ToArray(), 0); + } + + /// + /// Converts the [] to an . + /// + /// The bytes to convert. + /// Returns an . + [CLSCompliant(false)] + public static ulong GetUInt64(this IEnumerable bytes) + { + return BitConverter.ToUInt64(bytes.ToArray(), 0); + } } } diff --git a/X10D/src/CharExtensions.cs b/X10D/src/CharExtensions.cs index a377e09..cbdd49e 100644 --- a/X10D/src/CharExtensions.cs +++ b/X10D/src/CharExtensions.cs @@ -6,29 +6,29 @@ using System.Text; /// - /// Extension methods for . + /// Extension methods for . /// public static class CharExtensions { /// - /// Generates a new random string by filling it with characters found in . + /// Generates a new random string by filling it with characters found in . /// /// The character set. /// The length of the string to generate. - /// Returns a containing characters. + /// Returns a containing characters. public static string Random(this char[] chars, int length) { return chars.Random(length, RandomExtensions.Random); } /// - /// Generates a new random string by filling it with characters found in . + /// Generates a new random string by filling it with characters found in . /// /// The character set. /// The length of the string to generate. - /// The instance. - /// Returns a containing characters. - /// is . + /// The instance. + /// Returns a containing characters. + /// is . public static string Random(this char[] chars, int length, Random random) { if (chars is null) @@ -51,35 +51,37 @@ } /// - /// Generates a new random string by filling it with characters found in . + /// Generates a new random string by filling it with characters found in . /// /// The character set. /// The length of the string to generate. - /// Returns a containing characters. + /// Returns a containing characters. public static string Random(this IEnumerable chars, int length) { return chars.Random(length, RandomExtensions.Random); } /// - /// Generates a new random string by filling it with characters found in . + /// Generates a new random string by filling it with characters found in . /// /// The character set. /// The length of the string to generate. - /// The instance. - /// Returns a containing characters. + /// The instance. + /// Returns a containing characters. public static string Random(this IEnumerable chars, int length, Random random) { return chars.ToArray().Random(length, random); } /// - /// Repeats a character a specified number of times. + /// Repeats a character a specified number of times. /// /// The character to repeat. /// The repeat count. - /// Returns a whose value is repeated - /// times. + /// + /// Returns a whose value is repeated + /// times. + /// public static string Repeat(this char c, int count) { return new string(c, count); diff --git a/X10D/src/ComparableExtensions.cs b/X10D/src/ComparableExtensions.cs index bce366d..798112b 100644 --- a/X10D/src/ComparableExtensions.cs +++ b/X10D/src/ComparableExtensions.cs @@ -3,19 +3,21 @@ using System; /// - /// Extension methods for . + /// Extension methods for . /// public static class ComparableExtensions { /// - /// Determines if is between and . + /// Determines if is between and . /// /// The comparable type. /// The value to compare. /// The exclusive lower bound. /// The exclusive upper bound. - /// Returns if the value is between the bounds, - /// otherwise. + /// + /// Returns if the value is between the bounds, + /// otherwise. + /// public static bool Between(this T actual, T lower, T upper) where T : IComparable { diff --git a/X10D/src/ConvertibleExtensions.cs b/X10D/src/ConvertibleExtensions.cs index 6dad8b9..bf2a3ce 100644 --- a/X10D/src/ConvertibleExtensions.cs +++ b/X10D/src/ConvertibleExtensions.cs @@ -3,20 +3,22 @@ using System; /// - /// Extension methods for . + /// Extension methods for . /// public static class ConvertibleExtensions { /// - /// Converts the object to another type. + /// Converts the object to another type. /// /// The type to convert to. /// The object to convert. /// An object that supplies culture-specific formatting information. - /// Returns the value converted to . - /// This conversion is not supported. - /// -or- - /// is and is a value type. + /// Returns the value converted to . + /// + /// This conversion is not supported. + /// -or- + /// is and is a value type. + /// [CLSCompliant(false)] public static T To(this IConvertible value, IFormatProvider provider = null) { @@ -29,12 +31,12 @@ } /// - /// Converts the object to another type, returning the default value on failure. + /// Converts the object to another type, returning the default value on failure. /// /// The type to convert to. /// The object to convert. /// The format provider. - /// Returns the value converted to . + /// Returns the value converted to . /// This conversion is not supported. [CLSCompliant(false)] public static T ToOrDefault(this IConvertible value, IFormatProvider provider = null) @@ -43,13 +45,13 @@ } /// - /// Converts the object to another type, returning the default value on failure. + /// Converts the object to another type, returning the default value on failure. /// /// The type to convert to. /// The object to convert. /// The parameter where the result should be sent. /// An object that supplies culture-specific formatting information. - /// Returns on success, on failure. + /// Returns on success, on failure. [CLSCompliant(false)] public static bool ToOrDefault(this IConvertible value, out T newObj, IFormatProvider provider = null) { @@ -72,13 +74,42 @@ } /// - /// Converts the object to another type, returning a different value on failure. + /// Converts the object to another type, returning on failure. + /// + /// The type to convert to. + /// The object to convert. + /// An object that supplies culture-specific formatting information. + /// Returns a or . + [CLSCompliant(false)] + public static T ToOrNull(this IConvertible value, IFormatProvider provider = null) + where T : class + { + return value.ToOrNull(out T v, provider) ? v : null; + } + + /// + /// Converts the object to another type, returning on failure. + /// + /// The type to convert to. + /// The object to convert. + /// The parameter where the result should be sent. + /// An object that supplies culture-specific formatting information. + /// Returns a or . + [CLSCompliant(false)] + public static bool ToOrNull(this IConvertible value, out T newObj, IFormatProvider provider = null) + where T : class + { + return ToOrOther(value, out newObj, null, provider); + } + + /// + /// Converts the object to another type, returning a different value on failure. /// /// The type to convert to. /// The object to convert. /// The backup value. /// An object that supplies culture-specific formatting information. - /// Returns the value converted to . + /// Returns the value converted to . [CLSCompliant(false)] public static T ToOrOther(this IConvertible value, T other, IFormatProvider provider = null) { @@ -98,14 +129,14 @@ } /// - /// Converts the object to another type, returning a different value on failure. + /// Converts the object to another type, returning a different value on failure. /// /// The type to convert to. /// The object to convert. /// The parameter where the result should be sent. /// The backup value. /// An object that supplies culture-specific formatting information. - /// Returns on success, on failure. + /// Returns on success, on failure. [CLSCompliant(false)] public static bool ToOrOther(this IConvertible value, out T newObj, T other, IFormatProvider provider = null) { @@ -126,34 +157,5 @@ return false; } } - - /// - /// Converts the object to another type, returning on failure. - /// - /// The type to convert to. - /// The object to convert. - /// An object that supplies culture-specific formatting information. - /// Returns a or . - [CLSCompliant(false)] - public static T ToOrNull(this IConvertible value, IFormatProvider provider = null) - where T : class - { - return value.ToOrNull(out T v, provider) ? v : null; - } - - /// - /// Converts the object to another type, returning on failure. - /// - /// The type to convert to. - /// The object to convert. - /// The parameter where the result should be sent. - /// An object that supplies culture-specific formatting information. - /// Returns a or . - [CLSCompliant(false)] - public static bool ToOrNull(this IConvertible value, out T newObj, IFormatProvider provider = null) - where T : class - { - return ToOrOther(value, out newObj, null, provider); - } } } diff --git a/X10D/src/DateTimeExtensions.cs b/X10D/src/DateTimeExtensions.cs index d06bff8..84a559d 100644 --- a/X10D/src/DateTimeExtensions.cs +++ b/X10D/src/DateTimeExtensions.cs @@ -3,41 +3,43 @@ using System; /// - /// Extension methods for . + /// Extension methods for . /// public static class DateTimeExtensions { /// - /// Returns a rounded integer of the number of years since a given date as of today. + /// Returns a rounded integer of the number of years since a given date as of today. /// /// The date from which to start. - /// Returns the number of years since as of today. + /// Returns the number of years since as of today. public static int Age(this DateTime date) { return date.Age(DateTime.Today); } /// - /// Returns a rounded integer of the number of years since a given date as of another given date. + /// Returns a rounded integer of the number of years since a given date as of another given date. /// /// The date from which to start. /// The date at which to stop counting. - /// Returns the integer number of years since as of - /// . + /// + /// Returns the integer number of years since as of + /// . + /// public static int Age(this DateTime date, DateTime asOf) { return (int)(((asOf.Date - TimeSpan.FromDays(1) - date.Date).TotalDays + 1) / 365.2425); } /// - /// Gets a DateTime representing the first occurence of a specified day in the current month. + /// Gets a DateTime representing the first occurence of a specified day in the current month. /// /// The current day. /// The current day of week. - /// Returns a date representing the first occurence of . + /// Returns a date representing the first occurence of . public static DateTime First(this DateTime current, DayOfWeek dayOfWeek) { - DateTime first = current.FirstDayOfMonth(); + var first = current.FirstDayOfMonth(); if (first.DayOfWeek != dayOfWeek) { @@ -48,7 +50,7 @@ } /// - /// Gets a representing the first day in the current month. + /// Gets a representing the first day in the current month. /// /// The current date. /// Returns a date representing the first day of the month>. @@ -58,7 +60,24 @@ } /// - /// Gets a representing the last day in the current month. + /// Gets a representing the last specified day in the current month. + /// + /// The current date. + /// The current day of week. + /// Returns a date representing the final occurence of . + public static DateTime Last(this DateTime current, DayOfWeek dayOfWeek) + { + var last = current.LastDayOfMonth(); + var lastDayOfWeek = last.DayOfWeek; + + var diff = dayOfWeek - lastDayOfWeek; + var offset = diff > 0 ? diff - 7 : diff; + + return last.AddDays(offset); + } + + /// + /// Gets a representing the last day in the current month. /// /// The current date. /// Returns a date representing the last day of the month>. @@ -69,29 +88,12 @@ } /// - /// Gets a representing the last specified day in the current month. - /// - /// The current date. - /// The current day of week. - /// Returns a date representing the final occurence of . - public static DateTime Last(this DateTime current, DayOfWeek dayOfWeek) - { - DateTime last = current.LastDayOfMonth(); - DayOfWeek lastDayOfWeek = last.DayOfWeek; - - var diff = dayOfWeek - lastDayOfWeek; - var offset = diff > 0 ? diff - 7 : diff; - - return last.AddDays(offset); - } - - /// - /// Gets a representing the first date following the current date which falls on the - /// given day of the week. + /// Gets a representing the first date following the current date which falls on the + /// given day of the week. /// /// The current date. /// The day of week for the next date to get. - /// Returns a date representing the next occurence of . + /// Returns a date representing the next occurence of . public static DateTime Next(this DateTime current, DayOfWeek dayOfWeek) { var offsetDays = dayOfWeek - current.DayOfWeek; @@ -105,12 +107,14 @@ } /// - /// Converts the to a Unix timestamp. + /// Converts the to a Unix timestamp. /// - /// The instance. - /// Optional. Whether or not the return value should be represented as milliseconds. - /// Defaults to . - /// Returns a Unix timestamp representing the provided . + /// The instance. + /// + /// Optional. Whether or not the return value should be represented as milliseconds. + /// Defaults to . + /// + /// Returns a Unix timestamp representing the provided . public static long ToUnixTimeStamp(this DateTime time, bool useMillis = false) { DateTimeOffset offset = time; diff --git a/X10D/src/DictionaryExtensions.cs b/X10D/src/DictionaryExtensions.cs index 22e335c..8f12bee 100644 --- a/X10D/src/DictionaryExtensions.cs +++ b/X10D/src/DictionaryExtensions.cs @@ -6,17 +6,17 @@ using System.Web; /// - /// A set of extension methods for . + /// A set of extension methods for . /// public static class DictionaryExtensions { /// - /// Converts a to an object-relational-safe connection string. + /// Converts a to an object-relational-safe connection string. /// /// The key type. /// The value type. /// The dictionary. - /// Returns a representing the dictionary as a key=value; set. + /// Returns a representing the dictionary as a key=value; set. public static string ToConnectionString(this IReadOnlyDictionary dictionary) { static string SanitizeValue(T value) @@ -27,41 +27,41 @@ : value.ToString(); } - IEnumerable strings = dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value)}"); + var strings = dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value)}"); return string.Join(";", strings); } /// - /// Converts a to an object-relational-safe connection string. + /// Converts a to an object-relational-safe connection string. /// /// The key type. /// The value type. /// The dictionary. - /// Returns a representing the dictionary as a key=value; set. + /// Returns a representing the dictionary as a key=value; set. public static string ToConnectionString(this IDictionary dictionary) { return ((IReadOnlyDictionary)dictionary).ToConnectionString(); } /// - /// Converts a to an object-relational-safe connection string. + /// Converts a to an object-relational-safe connection string. /// /// The key type. /// The value type. /// The dictionary. - /// Returns a representing the dictionary as a key=value; set. + /// Returns a representing the dictionary as a key=value; set. public static string ToConnectionString(this Dictionary dictionary) { return ((IReadOnlyDictionary)dictionary).ToConnectionString(); } /// - /// Converts an to a HTTP GET parameter string. + /// Converts an to a HTTP GET parameter string. /// /// The key type. /// The value type. /// The dictionary. - /// Returns a representing the dictionary as a key=value& set. + /// Returns a representing the dictionary as a key=value& set. public static string ToGetParameters(this IReadOnlyDictionary dictionary) { static string Sanitize(KeyValuePair kvp) @@ -75,24 +75,24 @@ } /// - /// Converts an to a HTTP GET parameter string. + /// Converts an to a HTTP GET parameter string. /// /// The key type. /// The value type. /// The dictionary. - /// Returns a representing the dictionary as a key=value& set. + /// Returns a representing the dictionary as a key=value& set. public static string ToGetParameters(this IDictionary dictionary) { return ((IReadOnlyDictionary)dictionary).ToGetParameters(); } /// - /// Converts a to a HTTP GET parameter string. + /// Converts a to a HTTP GET parameter string. /// /// The key type. /// The value type. /// The dictionary. - /// Returns a representing the dictionary as a key=value& set. + /// Returns a representing the dictionary as a key=value& set. public static string ToGetParameters(this Dictionary dictionary) { return ((IReadOnlyDictionary)dictionary).ToGetParameters(); diff --git a/X10D/src/DoubleExtensions.cs b/X10D/src/DoubleExtensions.cs index 4566fcc..bd6e531 100644 --- a/X10D/src/DoubleExtensions.cs +++ b/X10D/src/DoubleExtensions.cs @@ -3,83 +3,89 @@ using System; /// - /// Extension methods for . + /// Extension methods for . /// public static class DoubleExtensions { /// - /// Clamps a value between a minimum and a maximum value. + /// Clamps a value between a minimum and a maximum value. /// /// The value to clamp. /// The minimum value. /// The maximum value. - /// Returns if is greater than it, - /// if is less than it, - /// or itself otherwise. + /// + /// Returns if is greater than it, + /// if is less than it, + /// or itself otherwise. + /// public static double Clamp(this double value, double min, double max) { return Math.Min(Math.Max(value, min), max); } /// - /// Converts an angle from degrees to radians. + /// Converts an angle from degrees to radians. /// /// The angle in degrees. - /// Returns in radians. + /// Returns in radians. public static double DegreesToRadians(this double angle) { - return Math.PI * angle / 180.0; + return (Math.PI * angle) / 180.0; } /// - /// Converts the to a []. + /// Converts the to a []. /// /// The number to convert. - /// Returns a []. + /// Returns a []. public static byte[] GetBytes(this double number) { return BitConverter.GetBytes(number); } /// - /// Determines if the is even. + /// Determines if the is even. /// /// The number. - /// Returns if is even, - /// otherwise. + /// + /// Returns if is even, + /// otherwise. + /// public static bool IsEven(this double number) { return Math.Abs(number % 2.0) < double.Epsilon; } /// - /// Determines if the is odd. + /// Determines if the is odd. /// /// The number. - /// Returns if is odd, - /// otherwise. + /// + /// Returns if is odd, + /// otherwise. + /// public static bool IsOdd(this double number) { return !number.IsEven(); } /// - /// Converts an angle from radians to degrees. + /// Converts an angle from radians to degrees. /// /// The angle in radians. - /// Returns in degrees. + /// Returns in degrees. public static double RadiansToDegrees(this double angle) { return angle * (180.0 / Math.PI); } /// - /// Rounds to the nearest value. + /// Rounds to the nearest value. /// /// The value to round. /// The nearest value. /// Returns the rounded value. - public static double Round(this double v, int nearest = 1) + public static double Round(this double v, double nearest = 1) { return Math.Round(v / nearest) * nearest; } diff --git a/X10D/src/EndPointExtensions.cs b/X10D/src/EndPointExtensions.cs index 885cd80..7da5099 100644 --- a/X10D/src/EndPointExtensions.cs +++ b/X10D/src/EndPointExtensions.cs @@ -3,38 +3,40 @@ using System.Net; /// - /// Extension methods for and derived types. + /// Extension methods for and derived types. /// public static class EndPointExtensions { /// - /// Gets the endpoint hostname. + /// Gets the endpoint hostname. /// /// The endpoint whose hostname to get. - /// Returns a representing the hostname, which may be an IP or a DNS, or empty - /// string on failure. + /// + /// Returns a representing the hostname, which may be an IP or a DNS, or empty + /// string on failure. + /// public static string GetHost(this EndPoint endPoint) { return endPoint switch { IPEndPoint ip => ip.Address.ToString(), DnsEndPoint dns => dns.Host, - _ => string.Empty, + var _ => string.Empty, }; } /// - /// Gets the endpoint port. + /// Gets the endpoint port. /// /// The endpoint whose port to get. - /// Returns an representing the port, or 0 on failure. + /// Returns an representing the port, or 0 on failure. public static int GetPort(this EndPoint endPoint) { return endPoint switch { IPEndPoint ip => ip.Port, DnsEndPoint dns => dns.Port, - _ => 0, + var _ => 0, }; } } diff --git a/X10D/src/EnumerableExtensions.cs b/X10D/src/EnumerableExtensions.cs index d82b0ff..9d09e43 100644 --- a/X10D/src/EnumerableExtensions.cs +++ b/X10D/src/EnumerableExtensions.cs @@ -4,21 +4,23 @@ using System.Linq; /// - /// Extension methods for . + /// Extension methods for . /// public static class EnumerableExtensions { /// - /// Splits into chunks of size . + /// Splits into chunks of size . /// /// Any type. /// The collection to split. - /// The maximum length of the nested collection. - /// Returns an of of - /// values. + /// The maximum length of the nested collection. + /// + /// Returns an of of + /// values. + /// public static IEnumerable> Split(this IEnumerable value, int chunkSize) { - T[] enumerable = value.ToArray(); + var enumerable = value.ToArray(); var count = enumerable.LongCount(); chunkSize = chunkSize.Clamp(1, enumerable.Length); diff --git a/X10D/src/Int16Extensions.cs b/X10D/src/Int16Extensions.cs index 205ef05..264891f 100644 --- a/X10D/src/Int16Extensions.cs +++ b/X10D/src/Int16Extensions.cs @@ -3,33 +3,37 @@ using System; /// - /// Extension methods for . + /// Extension methods for . /// public static class Int16Extensions { /// - /// Clamps a value between a minimum and a maximum value. + /// Clamps a value between a minimum and a maximum value. /// /// The value to clamp. /// The minimum value. /// The maximum value. - /// Returns if is greater than it, - /// if is less than it, - /// or itself otherwise. + /// + /// Returns if is greater than it, + /// if is less than it, + /// or itself otherwise. + /// public static short Clamp(this short value, short min, short max) { return Math.Min(Math.Max(value, min), max); } /// - /// Clamps a value between a minimum and a maximum value. + /// Clamps a value between a minimum and a maximum value. /// /// The value to clamp. /// The minimum value. /// The maximum value. - /// Returns if is greater than it, - /// if is less than it, - /// or itself otherwise. + /// + /// Returns if is greater than it, + /// if is less than it, + /// or itself otherwise. + /// [CLSCompliant(false)] public static ushort Clamp(this ushort value, ushort min, ushort max) { @@ -37,23 +41,27 @@ } /// - /// Converts the to a treating it as a Unix timestamp. + /// Converts the to a treating it as a Unix timestamp. /// /// The timestamp. - /// Optional. Whether or not the input value should be treated as milliseconds. Defaults - /// to .. - /// Returns a representing seconds since the Unix - /// epoch. + /// + /// Optional. Whether or not the input value should be treated as milliseconds. Defaults + /// to .. + /// + /// + /// Returns a representing seconds since the Unix + /// epoch. + /// public static DateTime FromUnixTimestamp(this short timestamp, bool isMillis = false) { return ((long)timestamp).FromUnixTimestamp(isMillis); } /// - /// Converts the to a []. + /// Converts the to a []. /// /// The number to convert. - /// Returns a []. + /// Returns a []. [CLSCompliant(false)] public static byte[] GetBytes(this ushort number) { @@ -61,32 +69,36 @@ } /// - /// Converts the to a []. + /// Converts the to a []. /// /// The number to convert. - /// Returns a []. + /// Returns a []. public static byte[] GetBytes(this short number) { return BitConverter.GetBytes(number); } /// - /// Determines if the is even. + /// Determines if the is even. /// /// The number. - /// Returns if is even, - /// otherwise. + /// + /// Returns if is even, + /// otherwise. + /// public static bool IsEven(this short number) { return ((long)number).IsEven(); } /// - /// Determines if the is even. + /// Determines if the is even. /// /// The number. - /// Returns if is even, - /// otherwise. + /// + /// Returns if is even, + /// otherwise. + /// [CLSCompliant(false)] public static bool IsEven(this ushort number) { @@ -94,22 +106,26 @@ } /// - /// Determines if the is odd. + /// Determines if the is odd. /// /// The number. - /// Returns if is odd, - /// otherwise. + /// + /// Returns if is odd, + /// otherwise. + /// public static bool IsOdd(this short number) { return !number.IsEven(); } /// - /// Determines if the is odd. + /// Determines if the is odd. /// /// The number. - /// Returns if is odd, - /// otherwise. + /// + /// Returns if is odd, + /// otherwise. + /// [CLSCompliant(false)] public static bool IsOdd(this ushort number) { @@ -117,22 +133,26 @@ } /// - /// Determines if the is a prime number. + /// Determines if the is a prime number. /// /// The number. - /// Returns if is prime, - /// otherwise. + /// + /// Returns if is prime, + /// otherwise. + /// public static bool IsPrime(this short number) { return ((long)number).IsPrime(); } /// - /// Determines if the is a prime number. + /// Determines if the is a prime number. /// /// The number. - /// Returns if is prime, - /// otherwise. + /// + /// Returns if is prime, + /// otherwise. + /// [CLSCompliant(false)] public static bool IsPrime(this ushort number) { @@ -140,22 +160,26 @@ } /// - /// Gets an boolean value that represents this integer. + /// Gets an boolean value that represents this integer. /// /// The integer. - /// Returns if is 0, - /// otherwise. + /// + /// Returns if is 0, + /// otherwise. + /// public static bool ToBoolean(this short value) { return ((long)value).ToBoolean(); } /// - /// Gets an boolean value that represents this integer. + /// Gets an boolean value that represents this integer. /// /// The integer. - /// Returns if is 0, - /// otherwise. + /// + /// Returns if is 0, + /// otherwise. + /// [CLSCompliant(false)] public static bool ToBoolean(this ushort value) { diff --git a/X10D/src/Int32Extensions.cs b/X10D/src/Int32Extensions.cs index 5c0c633..309cfe5 100644 --- a/X10D/src/Int32Extensions.cs +++ b/X10D/src/Int32Extensions.cs @@ -3,33 +3,37 @@ using System; /// - /// Extension methods for . + /// Extension methods for . /// public static class Int32Extensions { /// - /// Clamps a value between a minimum and a maximum value. + /// Clamps a value between a minimum and a maximum value. /// /// The value to clamp. /// The minimum value. /// The maximum value. - /// Returns if is greater than it, - /// if is less than it, - /// or itself otherwise. + /// + /// Returns if is greater than it, + /// if is less than it, + /// or itself otherwise. + /// public static int Clamp(this int value, int min, int max) { return Math.Min(Math.Max(value, min), max); } /// - /// Clamps a value between a minimum and a maximum value. + /// Clamps a value between a minimum and a maximum value. /// /// The value to clamp. /// The minimum value. /// The maximum value. - /// Returns if is greater than it, - /// if is less than it, - /// or itself otherwise. + /// + /// Returns if is greater than it, + /// if is less than it, + /// or itself otherwise. + /// [CLSCompliant(false)] public static uint Clamp(this uint value, uint min, uint max) { @@ -37,23 +41,27 @@ } /// - /// Converts the to a treating it as a Unix timestamp. + /// Converts the to a treating it as a Unix timestamp. /// /// The timestamp. - /// Optional. Whether or not the input value should be treated as milliseconds. Defaults - /// to .. - /// Returns a representing seconds since the Unix - /// epoch. + /// + /// Optional. Whether or not the input value should be treated as milliseconds. Defaults + /// to .. + /// + /// + /// Returns a representing seconds since the Unix + /// epoch. + /// public static DateTime FromUnixTimestamp(this int timestamp, bool isMillis = false) { return ((long)timestamp).FromUnixTimestamp(isMillis); } /// - /// Converts the to a []. + /// Converts the to a []. /// /// The number to convert. - /// Returns a []. + /// Returns a []. [CLSCompliant(false)] public static byte[] GetBytes(this uint number) { @@ -61,32 +69,36 @@ } /// - /// Converts the to a []. + /// Converts the to a []. /// /// The number to convert. - /// Returns a []. + /// Returns a []. public static byte[] GetBytes(this int number) { return BitConverter.GetBytes(number); } /// - /// Determines if the is even. + /// Determines if the is even. /// /// The number. - /// Returns if is even, - /// otherwise. + /// + /// Returns if is even, + /// otherwise. + /// public static bool IsEven(this int number) { return ((long)number).IsEven(); } /// - /// Determines if the is even. + /// Determines if the is even. /// /// The number. - /// Returns if is even, - /// otherwise. + /// + /// Returns if is even, + /// otherwise. + /// [CLSCompliant(false)] public static bool IsEven(this uint number) { @@ -94,22 +106,26 @@ } /// - /// Determines if the is odd. + /// Determines if the is odd. /// /// The number. - /// Returns if is odd, - /// otherwise. + /// + /// Returns if is odd, + /// otherwise. + /// public static bool IsOdd(this int number) { return !number.IsEven(); } /// - /// Determines if the is odd. + /// Determines if the is odd. /// /// The number. - /// Returns if is odd, - /// otherwise. + /// + /// Returns if is odd, + /// otherwise. + /// [CLSCompliant(false)] public static bool IsOdd(this uint number) { @@ -117,33 +133,39 @@ } /// - /// Determines if the is a prime number. + /// Determines if the is a prime number. /// /// The number. - /// Returns if is prime, - /// otherwise. + /// + /// Returns if is prime, + /// otherwise. + /// public static bool IsPrime(this int number) { return ((long)number).IsPrime(); } /// - /// Gets an boolean value that represents this integer. + /// Gets an boolean value that represents this integer. /// /// The integer. - /// Returns if is 0, - /// otherwise. + /// + /// Returns if is 0, + /// otherwise. + /// public static bool ToBoolean(this int value) { return ((long)value).ToBoolean(); } /// - /// Gets an boolean value that represents this integer. + /// Gets an boolean value that represents this integer. /// /// The integer. - /// Returns if is 0, - /// otherwise. + /// + /// Returns if is 0, + /// otherwise. + /// [CLSCompliant(false)] public static bool ToBoolean(this uint value) { diff --git a/X10D/src/Int64Extensions.cs b/X10D/src/Int64Extensions.cs index 579f353..8a54030 100644 --- a/X10D/src/Int64Extensions.cs +++ b/X10D/src/Int64Extensions.cs @@ -3,33 +3,37 @@ using System; /// - /// Extension methods for . + /// Extension methods for . /// public static class Int64Extensions { /// - /// Clamps a value between a minimum and a maximum value. + /// Clamps a value between a minimum and a maximum value. /// /// The value to clamp. /// The minimum value. /// The maximum value. - /// Returns if is greater than it, - /// if is less than it, - /// or itself otherwise. + /// + /// Returns if is greater than it, + /// if is less than it, + /// or itself otherwise. + /// public static long Clamp(this long value, long min, long max) { return Math.Min(Math.Max(value, min), max); } /// - /// Clamps a value between a minimum and a maximum value. + /// Clamps a value between a minimum and a maximum value. /// /// The value to clamp. /// The minimum value. /// The maximum value. - /// Returns if is greater than it, - /// if is less than it, - /// or itself otherwise. + /// + /// Returns if is greater than it, + /// if is less than it, + /// or itself otherwise. + /// [CLSCompliant(false)] public static ulong Clamp(this ulong value, ulong min, ulong max) { @@ -37,16 +41,20 @@ } /// - /// Converts the to a treating it as a Unix timestamp. + /// Converts the to a treating it as a Unix timestamp. /// /// The timestamp. - /// Optional. Whether or not the input value should be treated as milliseconds. Defaults - /// to . - /// Returns a representing seconds since the Unix - /// epoch. + /// + /// Optional. Whether or not the input value should be treated as milliseconds. Defaults + /// to . + /// + /// + /// Returns a representing seconds since the Unix + /// epoch. + /// public static DateTime FromUnixTimestamp(this long timestamp, bool isMillis = false) { - DateTimeOffset offset = isMillis + var offset = isMillis ? DateTimeOffset.FromUnixTimeMilliseconds(timestamp) : DateTimeOffset.FromUnixTimeSeconds(timestamp); @@ -54,10 +62,10 @@ } /// - /// Converts the to a []. + /// Converts the to a []. /// /// The number to convert. - /// Returns a []. + /// Returns a []. [CLSCompliant(false)] public static byte[] GetBytes(this ulong number) { @@ -65,32 +73,36 @@ } /// - /// Converts the to a []. + /// Converts the to a []. /// /// The number to convert. - /// Returns a []. + /// Returns a []. public static byte[] GetBytes(this long number) { return BitConverter.GetBytes(number); } /// - /// Determines if the is even. + /// Determines if the is even. /// /// The number. - /// Returns if is even, - /// otherwise. + /// + /// Returns if is even, + /// otherwise. + /// public static bool IsEven(this long number) { return Math.Abs(number % 2.0) < double.Epsilon; } /// - /// Determines if the is even. + /// Determines if the is even. /// /// The number. - /// Returns if is even, - /// otherwise. + /// + /// Returns if is even, + /// otherwise. + /// [CLSCompliant(false)] public static bool IsEven(this ulong number) { @@ -98,22 +110,26 @@ } /// - /// Determines if the is odd. + /// Determines if the is odd. /// /// The number. - /// Returns if is odd, - /// otherwise. + /// + /// Returns if is odd, + /// otherwise. + /// public static bool IsOdd(this long number) { return !IsEven(number); } /// - /// Determines if the is odd. + /// Determines if the is odd. /// /// The number. - /// Returns if is odd, - /// otherwise. + /// + /// Returns if is odd, + /// otherwise. + /// [CLSCompliant(false)] public static bool IsOdd(this ulong number) { @@ -121,11 +137,13 @@ } /// - /// Determines if the is a prime number. + /// Determines if the is a prime number. /// /// The number. - /// Returns if is prime, - /// otherwise. + /// + /// Returns if is prime, + /// otherwise. + /// public static bool IsPrime(this long number) { if (number <= 1) @@ -156,11 +174,13 @@ } /// - /// Determines if the is a prime number. + /// Determines if the is a prime number. /// /// The number. - /// Returns if is prime, - /// otherwise. + /// + /// Returns if is prime, + /// otherwise. + /// [CLSCompliant(false)] public static bool IsPrime(this ulong number) { @@ -192,22 +212,26 @@ } /// - /// Gets an boolean value that represents this integer. + /// Gets an boolean value that represents this integer. /// /// The integer. - /// Returns if is 0, - /// otherwise. + /// + /// Returns if is 0, + /// otherwise. + /// public static bool ToBoolean(this long value) { return value != 0; } /// - /// Gets an boolean value that represents this integer. + /// Gets an boolean value that represents this integer. /// /// The integer. - /// Returns if is 0, - /// otherwise. + /// + /// Returns if is 0, + /// otherwise. + /// [CLSCompliant(false)] public static bool ToBoolean(this ulong value) { diff --git a/X10D/src/ListExtensions.cs b/X10D/src/ListExtensions.cs index d98968f..e4e5086 100644 --- a/X10D/src/ListExtensions.cs +++ b/X10D/src/ListExtensions.cs @@ -5,97 +5,97 @@ using System.Linq; /// - /// Extension methods for . + /// Extension methods for . /// public static class ListExtensions { /// - /// Returns a random element from using a new instance. + /// Returns a random element from using a new instance. /// /// The collection type. /// The collection to draw from. - /// Returns a random element of type from . + /// Returns a random element of type from . public static T OneOf(this IEnumerable source) { return source.OneOf(new Random()); } /// - /// Returns a random element from using the instance. + /// Returns a random element from using the instance. /// /// The collection type. /// The collection to draw from. - /// The instance. - /// Returns a random element of type from . + /// The instance. + /// Returns a random element of type from . public static T OneOf(this IEnumerable source, Random random) { return source.ToList().OneOf(random); } /// - /// Returns a random element from using a new instance. + /// Returns a random element from using a new instance. /// /// The collection type. /// The collection to draw from. - /// Returns a random element of type from . + /// Returns a random element of type from . public static T OneOf(this IList source) { return source.OneOf(new Random()); } /// - /// Returns a random element from using the instance. + /// Returns a random element from using the instance. /// /// The collection type. /// The collection to draw from. - /// The instance. - /// Returns a random element of type from . + /// The instance. + /// Returns a random element of type from . public static T OneOf(this IList source, Random random) { return random.OneOf(source); } /// - /// Shuffles an enumerable. + /// Shuffles an enumerable. /// /// The collection type. /// The collection to shuffle. - /// Returns shuffled. + /// Returns shuffled. public static IEnumerable Shuffle(this IEnumerable source) { return source.Shuffle(new Random()); } /// - /// Shuffles an enumerable. + /// Shuffles an enumerable. /// /// The collection type. /// The collection to shuffle. - /// The instance. - /// Returns shuffled. + /// The instance. + /// Returns shuffled. public static IEnumerable Shuffle(this IEnumerable source, Random random) { return source.OrderBy(_ => random.Next()); } /// - /// Shuffles a list. + /// Shuffles a list. /// /// The collection type. /// The collection to shuffle. - /// Returns shuffled. + /// Returns shuffled. public static IEnumerable Shuffle(this IList source) { return source.Shuffle(new Random()); } /// - /// Shuffles a list. + /// Shuffles a list. /// /// The collection type. /// The collection to shuffle. - /// The instance. - /// Returns shuffled. + /// The instance. + /// Returns shuffled. public static IEnumerable Shuffle(this IList source, Random random) { return source.OrderBy(_ => random.Next()); diff --git a/X10D/src/RandomExtensions.cs b/X10D/src/RandomExtensions.cs index 99f8dcc..0008338 100644 --- a/X10D/src/RandomExtensions.cs +++ b/X10D/src/RandomExtensions.cs @@ -5,24 +5,26 @@ using System.Linq; /// - /// Extension methods for . + /// Extension methods for . /// public static class RandomExtensions { /// - /// Gets the instance to which other extension methods may refer, when one is - /// needed but not provided. + /// Gets the instance to which other extension methods may refer, when one is + /// needed but not provided. /// internal static Random Random { get; } = new Random(); /// - /// Returns either or based on 's next - /// generation. + /// Returns either or based on 's next + /// generation. /// - /// The instance. - /// Returns or depending on the return value - /// from . - /// is . + /// The instance. + /// + /// Returns or depending on the return value + /// from . + /// + /// is . public static bool CoinToss(this Random random) { if (random is null) @@ -34,26 +36,28 @@ } /// - /// Returns a random element from using the instance. + /// Returns a random element from using the instance. /// /// The collection type. - /// The instance. + /// The instance. /// The collection from which to draw. - /// Returns a random element of type from . + /// Returns a random element of type from . public static T OneOf(this Random random, params T[] source) { return source.ToList().OneOf(random); } /// - /// Returns a random element from using the instance. + /// Returns a random element from using the instance. /// /// The collection type. - /// The instance. + /// The instance. /// The collection from which to draw. - /// Returns a random element of type from . - /// or is - /// . + /// Returns a random element of type from . + /// + /// or is + /// . + /// public static T OneOf(this Random random, IList source) { if (random is null) diff --git a/X10D/src/ReflectionExtensions.cs b/X10D/src/ReflectionExtensions.cs index 25fbc54..ff3cb23 100644 --- a/X10D/src/ReflectionExtensions.cs +++ b/X10D/src/ReflectionExtensions.cs @@ -5,18 +5,20 @@ using System.Reflection; /// - /// Extension methods for various reflection types. + /// Extension methods for various reflection types. /// public static class ReflectionExtensions { /// - /// Gets the value set in this member's annotated , or - /// if none exists. + /// Gets the value set in this member's annotated , or + /// if none exists. /// /// The member. - /// Returns an representing the value stored in this member's - /// . - /// is . + /// + /// Returns an representing the value stored in this member's + /// . + /// + /// is . public static object GetDefaultValue(this MemberInfo member) { if (member is null) @@ -33,14 +35,16 @@ } /// - /// Gets the value set in this member's annotated , or - /// if none exists. + /// Gets the value set in this member's annotated , or + /// if none exists. /// /// The type to which the value should cast. /// The member. - /// Returns an instance of representing the value stored in this member's - /// . - /// is . + /// + /// Returns an instance of representing the value stored in this member's + /// . + /// + /// is . public static T GetDefaultValue(this MemberInfo member) { if (member is null) @@ -52,13 +56,15 @@ } /// - /// Gets the value set in this member's annotated , or - /// if none exists. + /// Gets the value set in this member's annotated , or + /// if none exists. /// /// The member. - /// Returns an instance of representing the value stored in this member's - /// . - /// is . + /// + /// Returns a string representing the value stored in this member's + /// . + /// + /// is . public static string GetDescription(this MemberInfo member) { if (member is null) @@ -75,18 +81,22 @@ } /// - /// Retrieves a custom attribute of a specified type that is applied to the specified member, and passes it - /// to a selector delegate in order to select one or more the members in the attribute. + /// Retrieves a custom attribute of a specified type that is applied to the specified member, and passes it + /// to a selector delegate in order to select one or more the members in the attribute. /// /// The attribute type. - /// The return type of the delegate. + /// The return type of the delegate. /// The member. /// The selector delegate. - /// Returns an instance of as provided from - /// . - /// is - /// -or- - /// is . + /// + /// Returns an instance of as provided from + /// . + /// + /// + /// is + /// -or- + /// is . + /// public static TReturn SelectFromCustomAttribute( this MemberInfo member, Func selector) diff --git a/X10D/src/SingleExtensions.cs b/X10D/src/SingleExtensions.cs index b62c6a6..53f6925 100644 --- a/X10D/src/SingleExtensions.cs +++ b/X10D/src/SingleExtensions.cs @@ -3,83 +3,89 @@ using System; /// - /// Extension methods for . + /// Extension methods for . /// public static class SingleExtensions { /// - /// Clamps a value between a minimum and a maximum value. + /// Clamps a value between a minimum and a maximum value. /// /// The value to clamp. /// The minimum value. /// The maximum value. - /// Returns if is greater than it, - /// if is less than it, - /// or itself otherwise. + /// + /// Returns if is greater than it, + /// if is less than it, + /// or itself otherwise. + /// public static float Clamp(this float value, float min, float max) { return Math.Min(Math.Max(value, min), max); } /// - /// Converts an angle from degrees to radians. + /// Converts an angle from degrees to radians. /// /// The angle in degrees. - /// Returns in radians. + /// Returns in radians. public static float DegreesToRadians(this float angle) { return (float)((double)angle).DegreesToRadians(); } /// - /// Converts the to a []. + /// Converts the to a []. /// /// The number to convert. - /// Returns a []. + /// Returns a []. public static byte[] GetBytes(this float number) { return BitConverter.GetBytes(number); } /// - /// Determines if the is even. + /// Determines if the is even. /// /// The number. - /// Returns if is even, - /// otherwise. + /// + /// Returns if is even, + /// otherwise. + /// public static bool IsEven(this float number) { return ((double)number).IsEven(); } /// - /// Determines if the is odd. + /// Determines if the is odd. /// /// The number. - /// Returns if is odd, - /// otherwise. + /// + /// Returns if is odd, + /// otherwise. + /// public static bool IsOdd(this float number) { return !number.IsEven(); } /// - /// Converts an angle from radians to degrees. + /// Converts an angle from radians to degrees. /// /// The angle in radians. - /// Returns in degrees. + /// Returns in degrees. public static float RadiansToDegrees(this float angle) { return (float)((double)angle).RadiansToDegrees(); } /// - /// Rounds to the nearest value. + /// Rounds to the nearest value. /// /// The value to round. /// The nearest value. /// Returns the rounded value. - public static float Round(this float v, int nearest = 1) + public static float Round(this float v, float nearest = 1) { return (float)((double)v).Round(nearest); } diff --git a/X10D/src/StreamExtensions.cs b/X10D/src/StreamExtensions.cs index bdbb6c5..521796b 100644 --- a/X10D/src/StreamExtensions.cs +++ b/X10D/src/StreamExtensions.cs @@ -2,21 +2,20 @@ { using System; using System.IO; - using System.Reflection; using System.Security.Cryptography; /// - /// Extension methods for . + /// Extension methods for . /// public static class StreamExtensions { /// - /// Returns the hash of a stream using the specified hashing algorithm. + /// Returns the hash of a stream using the specified hashing algorithm. /// - /// A derived type. + /// A derived type. /// The stream whose hash is to be computed. - /// Returns a array representing the hash of the stream. - /// is . + /// Returns a array representing the hash of the stream. + /// is . public static byte[] GetHash(this Stream stream) where T : HashAlgorithm { @@ -25,7 +24,7 @@ throw new ArgumentNullException(nameof(stream)); } - MethodInfo create = typeof(T).GetMethod("Create", Array.Empty()); + var create = typeof(T).GetMethod("Create", Array.Empty()); using var crypt = (T)create?.Invoke(null, null); return crypt?.ComputeHash(stream); } diff --git a/X10D/src/StringExtensions.cs b/X10D/src/StringExtensions.cs index 4743075..a462ad4 100644 --- a/X10D/src/StringExtensions.cs +++ b/X10D/src/StringExtensions.cs @@ -8,12 +8,12 @@ using System.Text; /// - /// Extension methods for . + /// Extension methods for . /// public static class StringExtensions { /// - /// Decodes a base-64 encoded string. + /// Decodes a base-64 encoded string. /// /// The base-64 string to decode. /// Returns the string in plain text. @@ -23,7 +23,7 @@ } /// - /// Encodes a base-64 encoded string. + /// Encodes a base-64 encoded string. /// /// The plain text string to decode. /// Returns the string in plain text. @@ -33,18 +33,22 @@ } /// - /// Converts this string from one encoding to another. + /// Converts this string from one encoding to another. /// /// The input string. /// The input encoding. /// The output encoding. - /// Returns a new with its data converted to - /// . - /// is - /// - or - - /// is - /// -or - /// is . + /// + /// Returns a new with its data converted to + /// . + /// + /// + /// is + /// - or - + /// is + /// -or + /// is . + /// public static string ChangeEncoding(this string str, Encoding from, Encoding to) { if (str is null) @@ -66,27 +70,31 @@ } /// - /// Parses a into an . + /// Parses a into an . /// - /// The type of the . - /// The value to parse. - /// The value corresponding to the . - /// Credit for this method goes to Scott Dorman: - /// (http://geekswithblogs.net/sdorman/Default.aspx) + /// The type of the . + /// The value to parse. + /// The value corresponding to the . + /// + /// Credit for this method goes to Scott Dorman: + /// (http://geekswithblogs.net/sdorman/Default.aspx). + /// public static T EnumParse(this string value) { return value.EnumParse(false); } /// - /// Parses a into an . + /// Parses a into an . /// - /// The type of the . - /// The value to parse. + /// The type of the . + /// The value to parse. /// Whether or not to ignore casing. - /// The value corresponding to the . - /// Credit for this method goes to Scott Dorman: - /// (http://geekswithblogs.net/sdorman/Default.aspx) + /// The value corresponding to the . + /// + /// Credit for this method goes to Scott Dorman: + /// (http://geekswithblogs.net/sdorman/Default.aspx). + /// public static T EnumParse(this string value, bool ignoreCase) { if (value is null) @@ -101,7 +109,7 @@ throw new ArgumentException(Resource.EnumParseEmptyStringException, nameof(value)); } - Type t = typeof(T); + var t = typeof(T); if (!t.IsEnum) { @@ -112,24 +120,26 @@ } /// - /// Gets a [] representing the value the with - /// encoding. + /// Gets a [] representing the value the with + /// encoding. /// /// The string to convert. - /// Returns a []. + /// Returns a []. public static byte[] GetBytes(this string str) { return str.GetBytes(Encoding.UTF8); } /// - /// Gets a [] representing the value the with the provided encoding. + /// Gets a [] representing the value the with the provided encoding. /// /// The string to convert. /// The encoding to use. - /// Returns a []. - /// or or both are - /// . + /// Returns a []. + /// + /// or or both are + /// . + /// public static byte[] GetBytes(this string str, Encoding encoding) { if (str is null) @@ -146,46 +156,50 @@ } /// - /// Determines if all alpha characters in this string are considered lowercase. + /// Determines if all alpha characters in this string are considered lowercase. /// /// The input string. - /// Returns if all alpha characters are lowercase, - /// otherwise. + /// + /// Returns if all alpha characters are lowercase, + /// otherwise. + /// public static bool IsLower(this string str) { return str.Where(char.IsLetter).All(char.IsLower); } /// - /// Determines if all alpha characters in this string are considered uppercase. + /// Determines if all alpha characters in this string are considered uppercase. /// /// The input string. - /// Returns if all alpha characters are uppercase, - /// otherwise. + /// + /// Returns if all alpha characters are uppercase, + /// otherwise. + /// public static bool IsUpper(this string str) { return str.Where(char.IsLetter).All(char.IsUpper); } /// - /// Generates a new random string by filling it with characters found in . + /// Generates a new random string by filling it with characters found in . /// /// The character set. /// The length of the string to generate. - /// Returns a containing characters. + /// Returns a containing characters. public static string Random(this string str, int length) { return str.Random(length, RandomExtensions.Random); } /// - /// Generates a new random string by filling it with characters found in . + /// Generates a new random string by filling it with characters found in . /// /// The character set. /// The length of the string to generate. - /// The instance. - /// Returns a containing characters. - /// is . + /// The instance. + /// Returns a containing characters. + /// is . public static string Random(this string str, int length, Random random) { if (str is null) @@ -197,13 +211,15 @@ } /// - /// Repeats a string a specified number of times. + /// Repeats a string a specified number of times. /// /// The string to repeat. /// The repeat count. - /// Returns a whose value is repeated - /// times. - /// is . + /// + /// Returns a whose value is repeated + /// times. + /// + /// is . public static string Repeat(this string str, int count) { if (str is null) @@ -222,22 +238,22 @@ } /// - /// Shuffles the characters in the string. + /// Shuffles the characters in the string. /// /// The string to shuffle. - /// Returns a containing the characters in , rearranged. + /// Returns a containing the characters in , rearranged. public static string Shuffle(this string str) { return str.Shuffle(RandomExtensions.Random); } /// - /// Shuffles the characters in the string. + /// Shuffles the characters in the string. /// /// The string to shuffle. - /// The instance. - /// Returns a containing the characters in , rearranged. - /// is . + /// The instance. + /// Returns a containing the characters in , rearranged. + /// is . public static string Shuffle(this string str, Random random) { if (str is null) @@ -249,13 +265,15 @@ } /// - /// Splits the into chunks that are no greater than in length. + /// Splits the into chunks that are no greater than in length. /// /// The string to split. /// The maximum length of each string in the returned result. - /// Returns an containing instances which are no - /// greater than in length. - /// is . + /// + /// Returns an containing instances which are no + /// greater than in length. + /// + /// is . public static IEnumerable Split(this string str, int chunkSize) { if (str is null) @@ -275,11 +293,11 @@ } /// - /// Converts a to a . + /// Converts a to a . /// /// The string to convert. - /// Returns a . - /// is . + /// Returns a . + /// is . public static SecureString ToSecureString(this string str) { if (str is null) @@ -302,12 +320,12 @@ } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. + /// The to convert. /// Whether or not to use this extension method. - /// Returns a . - /// is . + /// Returns a . + /// is . public static string ToString(this SecureString str, bool extension) { if (str is null) @@ -319,12 +337,12 @@ } /// - /// Parses a shorthand time span string (e.g. 3w 2d 1.5h) and converts it to an instance of - /// . + /// Parses a shorthand time span string (e.g. 3w 2d 1.5h) and converts it to an instance of + /// . /// /// The input string. - /// Returns an instance of . - /// is . + /// Returns an instance of . + /// is . public static TimeSpan ToTimeSpan(this string str) { if (str is null) diff --git a/X10D/src/StructExtensions.cs b/X10D/src/StructExtensions.cs index 563373a..cb9aac7 100644 --- a/X10D/src/StructExtensions.cs +++ b/X10D/src/StructExtensions.cs @@ -3,18 +3,20 @@ using System; /// - /// Extension methods for types. + /// Extension methods for types. /// public static class StructExtensions { /// - /// Returns the next value in an using the specified value as a starting point. + /// Returns the next value in an using the specified value as a starting point. /// - /// An . - /// An value. - /// Optional. Whether or not to wrap to the to the start of the enum. Defaults to - /// true. - /// Returns a value. + /// An . + /// An value. + /// + /// Optional. Whether or not to wrap to the to the start of the enum. Defaults to + /// true. + /// + /// Returns a value. public static T Next(this T src, bool wrap = true) where T : struct { @@ -29,13 +31,15 @@ } /// - /// Returns the previous value in an using the specified value as a starting point. + /// Returns the previous value in an using the specified value as a starting point. /// - /// An . - /// An value. - /// Optional. Whether or not to wrap to the to the end of the enum. Defaults to - /// true. - /// Returns a value. + /// An . + /// An value. + /// + /// Optional. Whether or not to wrap to the to the end of the enum. Defaults to + /// true. + /// + /// Returns a value. public static T Previous(this T src, bool wrap = true) where T : struct { diff --git a/X10D/src/TimeSpanParser.cs b/X10D/src/TimeSpanParser.cs index 39e6176..5f5a7aa 100644 --- a/X10D/src/TimeSpanParser.cs +++ b/X10D/src/TimeSpanParser.cs @@ -5,17 +5,17 @@ using System.Text.RegularExpressions; /// - /// Represents a class which contains a parser which converts into . + /// Represents a class which contains a parser which converts into . /// public static class TimeSpanParser { /// - /// Parses a shorthand time span string (e.g. 3w 2d 1.5h) and converts it to an instance of - /// . + /// Parses a shorthand time span string (e.g. 3w 2d 1.5h) and converts it to an instance of + /// . /// /// The input string. /// The format provider. - /// Returns an instance of . + /// Returns an instance of . public static TimeSpan Parse(string input, IFormatProvider provider = null) { const string realNumberPattern = @"([0-9]*\.[0-9]+|[0-9]+)"; @@ -26,7 +26,7 @@ $"(?:{realNumberPattern} *s)? *" + $"(?:{realNumberPattern} *ms)?$"; - Match match = Regex.Match(input, pattern); + var match = Regex.Match(input, pattern); double weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0, milliseconds = 0; if (match.Groups[1].Success) @@ -62,7 +62,7 @@ Trace.WriteLine($"Input: {input}"); Trace.WriteLine($"Parsed: {weeks}w {days}d {hours}h {minutes}m {seconds}s {milliseconds}ms"); - TimeSpan span = TimeSpan.Zero; + var span = TimeSpan.Zero; span += TimeSpan.FromDays(weeks * 7); span += TimeSpan.FromDays(days);