1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 23:58:48 +00:00

🧹 Code style cleanup

This commit is contained in:
Oliver Booth 2020-07-15 14:31:02 +01:00
parent e747921fb7
commit f8541fd239
23 changed files with 813 additions and 907 deletions

View File

@ -1,195 +1,215 @@
# All files
[*]
guidelines = 130
# C# files # C# files
[*.cs] [*.cs]
#### Core EditorConfig Options #### #### Core EditorConfig Options ####
# Indentation and spacing # Indentation and spacing
indent_size = 4 indent_size=4
indent_style = space indent_style=space
tab_width = 4 tab_width=4
# New line preferences # New line preferences
end_of_line = crlf end_of_line=crlf
insert_final_newline = true insert_final_newline=true
#### .NET Coding Conventions #### #### .NET Coding Conventions ####
# Organize usings # Organize usings
dotnet_separate_import_directive_groups = false dotnet_separate_import_directive_groups=false
dotnet_sort_system_directives_first = true dotnet_sort_system_directives_first=true
# this. and Me. preferences # this. and Me. preferences
dotnet_style_qualification_for_event = true:suggestion dotnet_style_qualification_for_event=true:suggestion
dotnet_style_qualification_for_field = true:suggestion dotnet_style_qualification_for_field=true:suggestion
dotnet_style_qualification_for_method = true:suggestion dotnet_style_qualification_for_method=true:suggestion
dotnet_style_qualification_for_property = true:suggestion dotnet_style_qualification_for_property=true:suggestion
# Language keywords vs BCL types preferences # Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:warning dotnet_style_predefined_type_for_locals_parameters_members=true:warning
dotnet_style_predefined_type_for_member_access = true:warning dotnet_style_predefined_type_for_member_access=true:warning
# Parentheses preferences # Parentheses preferences
dotnet_style_parentheses_in_arithmetic_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_binary_operators=always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary: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_relational_binary_operators=always_for_clarity:silent
# Modifier preferences # 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 # Expression-level preferences
dotnet_style_coalesce_expression = true:suggestion dotnet_style_coalesce_expression=true:suggestion
dotnet_style_collection_initializer = true:suggestion dotnet_style_collection_initializer=true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion dotnet_style_explicit_tuple_names=true:suggestion
dotnet_style_null_propagation = true:suggestion dotnet_style_null_propagation=true:suggestion
dotnet_style_object_initializer = true:suggestion dotnet_style_object_initializer=true:suggestion
dotnet_style_prefer_auto_properties = true:silent dotnet_style_prefer_auto_properties=true:silent
dotnet_style_prefer_compound_assignment = true:suggestion dotnet_style_prefer_compound_assignment=true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent dotnet_style_prefer_conditional_expression_over_assignment=true:silent
dotnet_style_prefer_conditional_expression_over_return = 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_anonymous_type_member_names=false:suggestion
dotnet_style_prefer_inferred_tuple_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_is_null_check_over_reference_equality_method=true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion dotnet_style_prefer_simplified_interpolation=true:suggestion
# Field preferences # Field preferences
dotnet_style_readonly_field = true:suggestion dotnet_style_readonly_field=true:suggestion
# Parameter preferences # Parameter preferences
dotnet_code_quality_unused_parameters = all:suggestion dotnet_code_quality_unused_parameters=all:suggestion
#### C# Coding Conventions #### #### C# Coding Conventions ####
# var preferences # var preferences
csharp_style_var_elsewhere = false:warning csharp_style_var_elsewhere=true:warning
csharp_style_var_for_built_in_types = true:warning csharp_style_var_when_type_is_apparent=true:warning
csharp_style_var_when_type_is_apparent = true:warning csharp_style_var_for_built_in_types=true:warning
# Expression-bodied members # Expression-bodied members
csharp_style_expression_bodied_accessors = true:suggestion csharp_style_expression_bodied_accessors=true:suggestion
csharp_style_expression_bodied_constructors = false:suggestion csharp_style_expression_bodied_constructors=false:suggestion
csharp_style_expression_bodied_indexers = true:suggestion csharp_style_expression_bodied_indexers=true:suggestion
csharp_style_expression_bodied_lambdas = true:silent csharp_style_expression_bodied_lambdas=true:silent
csharp_style_expression_bodied_local_functions = false:silent csharp_style_expression_bodied_local_functions=false:silent
csharp_style_expression_bodied_methods = false:suggestion csharp_style_expression_bodied_methods=false:suggestion
csharp_style_expression_bodied_operators = true:suggestion csharp_style_expression_bodied_operators=false:suggestion
csharp_style_expression_bodied_properties = false:suggestion csharp_style_expression_bodied_properties=false:suggestion
# Pattern matching preferences # Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = 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_pattern_matching_over_is_with_cast_check=true:suggestion
csharp_style_prefer_switch_expression = true:suggestion csharp_style_prefer_switch_expression=true:suggestion
# Null-checking preferences # Null-checking preferences
csharp_style_conditional_delegate_call = true:suggestion csharp_style_conditional_delegate_call=true:suggestion
# Modifier preferences # Modifier preferences
csharp_prefer_static_local_function = true:suggestion 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_preferred_modifier_order=public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
# Code-block preferences # Code-block preferences
csharp_prefer_braces = true:suggestion csharp_prefer_braces=true:suggestion
csharp_prefer_simple_using_statement = true:suggestion csharp_prefer_simple_using_statement=true:suggestion
# Expression-level preferences # Expression-level preferences
csharp_prefer_simple_default_expression = true:suggestion csharp_prefer_simple_default_expression=true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion csharp_style_deconstructed_variable_declaration=true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion csharp_style_inlined_variable_declaration=true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion csharp_style_pattern_local_over_anonymous_function=true:suggestion
csharp_style_prefer_index_operator = true:suggestion csharp_style_prefer_index_operator=true:suggestion
csharp_style_prefer_range_operator = true:suggestion csharp_style_prefer_range_operator=true:suggestion
csharp_style_throw_expression = true:suggestion csharp_style_throw_expression=true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion csharp_style_unused_value_assignment_preference=discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent csharp_style_unused_value_expression_statement_preference=discard_variable:silent
# 'using' directive preferences # 'using' directive preferences
csharp_using_directive_placement = inside_namespace:suggestion csharp_using_directive_placement=inside_namespace:suggestion
#### C# Formatting Rules #### #### C# Formatting Rules ####
max_line_length=130
# New line preferences # New line preferences
csharp_new_line_before_catch = true csharp_new_line_before_catch=true
csharp_new_line_before_else = true csharp_new_line_before_else=true
csharp_new_line_before_finally = true csharp_new_line_before_finally=true
csharp_new_line_before_members_in_anonymous_types = true csharp_new_line_before_members_in_anonymous_types=true
csharp_new_line_before_members_in_object_initializers = true csharp_new_line_before_members_in_object_initializers=true
csharp_new_line_before_open_brace = all csharp_new_line_before_open_brace=all
csharp_new_line_between_query_expression_clauses = true csharp_new_line_between_query_expression_clauses=true
# Indentation preferences # Indentation preferences
csharp_indent_block_contents = true csharp_indent_block_contents=true
csharp_indent_braces = false csharp_indent_braces=false
csharp_indent_case_contents = true csharp_indent_case_contents=true
csharp_indent_case_contents_when_block = true csharp_indent_case_contents_when_block=true
csharp_indent_labels = one_less_than_current csharp_indent_labels=one_less_than_current
csharp_indent_switch_labels = true csharp_indent_switch_labels=true
# Space preferences # Space preferences
csharp_space_after_cast = false csharp_space_after_cast=false
csharp_space_after_colon_in_inheritance_clause = true csharp_space_after_colon_in_inheritance_clause=true
csharp_space_after_comma = true csharp_space_after_comma=true
csharp_space_after_dot = false csharp_space_after_dot=false
csharp_space_after_keywords_in_control_flow_statements = true csharp_space_after_keywords_in_control_flow_statements=true
csharp_space_after_semicolon_in_for_statement = true csharp_space_after_semicolon_in_for_statement=true
csharp_space_around_binary_operators = before_and_after csharp_space_around_binary_operators=before_and_after
csharp_space_around_declaration_statements = false csharp_space_around_declaration_statements=false
csharp_space_before_colon_in_inheritance_clause = true csharp_space_before_colon_in_inheritance_clause=true
csharp_space_before_comma = false csharp_space_before_comma=false
csharp_space_before_dot = false csharp_space_before_dot=false
csharp_space_before_open_square_brackets = false csharp_space_before_open_square_brackets=false
csharp_space_before_semicolon_in_for_statement = false csharp_space_before_semicolon_in_for_statement=false
csharp_space_between_empty_square_brackets = false csharp_space_between_empty_square_brackets=false
csharp_space_between_method_call_empty_parameter_list_parentheses = 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_name_and_opening_parenthesis=false
csharp_space_between_method_call_parameter_list_parentheses = 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_empty_parameter_list_parentheses=false
csharp_space_between_method_declaration_name_and_open_parenthesis = false csharp_space_between_method_declaration_name_and_open_parenthesis=false
csharp_space_between_method_declaration_parameter_list_parentheses = false csharp_space_between_method_declaration_parameter_list_parentheses=false
csharp_space_between_parentheses = false csharp_space_between_parentheses=false
csharp_space_between_square_brackets = false csharp_space_between_square_brackets=false
# Wrapping preferences # Wrapping preferences
csharp_preserve_single_line_blocks = true csharp_preserve_single_line_blocks=true
csharp_preserve_single_line_statements = true csharp_preserve_single_line_statements=true
#### Naming styles #### #### Naming styles ####
# Naming rules # Naming rules
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion 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.symbols=interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i 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.severity=suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types 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.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.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.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.style=pascal_case
# Symbol specifications # Symbol specifications
dotnet_naming_symbols.interface.applicable_kinds = interface 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.applicable_accessibilities=public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers = dotnet_naming_symbols.interface.required_modifiers=
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum 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.applicable_accessibilities=public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers = dotnet_naming_symbols.types.required_modifiers=
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method 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.applicable_accessibilities=public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers = dotnet_naming_symbols.non_field_members.required_modifiers=
# Naming styles # Naming styles
dotnet_naming_style.pascal_case.required_prefix = dotnet_naming_style.pascal_case.required_prefix=
dotnet_naming_style.pascal_case.required_suffix = dotnet_naming_style.pascal_case.required_suffix=
dotnet_naming_style.pascal_case.word_separator = dotnet_naming_style.pascal_case.word_separator=
dotnet_naming_style.pascal_case.capitalization = pascal_case dotnet_naming_style.pascal_case.capitalization=pascal_case
dotnet_naming_style.begins_with_i.required_prefix = I dotnet_naming_style.begins_with_i.required_prefix=I
dotnet_naming_style.begins_with_i.required_suffix = dotnet_naming_style.begins_with_i.required_suffix=
dotnet_naming_style.begins_with_i.word_separator = dotnet_naming_style.begins_with_i.word_separator=
dotnet_naming_style.begins_with_i.capitalization = pascal_case 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

View File

@ -1,259 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="X10D" Description=" " ToolsVersion="16.0">
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1000" Action="Warning" />
<Rule Id="CA1001" Action="Warning" />
<Rule Id="CA1002" Action="Warning" />
<Rule Id="CA1003" Action="Warning" />
<Rule Id="CA1004" Action="Warning" />
<Rule Id="CA1005" Action="Warning" />
<Rule Id="CA1006" Action="Warning" />
<Rule Id="CA1007" Action="Warning" />
<Rule Id="CA1008" Action="Warning" />
<Rule Id="CA1009" Action="Warning" />
<Rule Id="CA1010" Action="Warning" />
<Rule Id="CA1011" Action="Warning" />
<Rule Id="CA1012" Action="Warning" />
<Rule Id="CA1013" Action="Warning" />
<Rule Id="CA1014" Action="Warning" />
<Rule Id="CA1016" Action="Warning" />
<Rule Id="CA1017" Action="Warning" />
<Rule Id="CA1018" Action="Warning" />
<Rule Id="CA1019" Action="Warning" />
<Rule Id="CA1020" Action="Warning" />
<Rule Id="CA1021" Action="Warning" />
<Rule Id="CA1023" Action="Warning" />
<Rule Id="CA1024" Action="Warning" />
<Rule Id="CA1025" Action="Warning" />
<Rule Id="CA1026" Action="Warning" />
<Rule Id="CA1027" Action="Warning" />
<Rule Id="CA1028" Action="Warning" />
<Rule Id="CA1030" Action="Warning" />
<Rule Id="CA1031" Action="Warning" />
<Rule Id="CA1032" Action="Warning" />
<Rule Id="CA1033" Action="Warning" />
<Rule Id="CA1034" Action="Warning" />
<Rule Id="CA1035" Action="Warning" />
<Rule Id="CA1036" Action="Warning" />
<Rule Id="CA1038" Action="Warning" />
<Rule Id="CA1039" Action="Warning" />
<Rule Id="CA1040" Action="Warning" />
<Rule Id="CA1041" Action="Warning" />
<Rule Id="CA1043" Action="Warning" />
<Rule Id="CA1044" Action="Warning" />
<Rule Id="CA1045" Action="Warning" />
<Rule Id="CA1046" Action="Warning" />
<Rule Id="CA1047" Action="Warning" />
<Rule Id="CA1048" Action="Warning" />
<Rule Id="CA1049" Action="Warning" />
<Rule Id="CA1050" Action="Warning" />
<Rule Id="CA1051" Action="Warning" />
<Rule Id="CA1052" Action="Warning" />
<Rule Id="CA1053" Action="Warning" />
<Rule Id="CA1054" Action="Warning" />
<Rule Id="CA1055" Action="Warning" />
<Rule Id="CA1056" Action="Warning" />
<Rule Id="CA1057" Action="Warning" />
<Rule Id="CA1058" Action="Warning" />
<Rule Id="CA1059" Action="Warning" />
<Rule Id="CA1060" Action="Warning" />
<Rule Id="CA1061" Action="Warning" />
<Rule Id="CA1062" Action="Warning" />
<Rule Id="CA1063" Action="Warning" />
<Rule Id="CA1064" Action="Warning" />
<Rule Id="CA1065" Action="Warning" />
<Rule Id="CA1300" Action="Warning" />
<Rule Id="CA1301" Action="Warning" />
<Rule Id="CA1302" Action="Warning" />
<Rule Id="CA1303" Action="Warning" />
<Rule Id="CA1304" Action="Warning" />
<Rule Id="CA1305" Action="Warning" />
<Rule Id="CA1306" Action="Warning" />
<Rule Id="CA1307" Action="Warning" />
<Rule Id="CA1308" Action="Warning" />
<Rule Id="CA1309" Action="Warning" />
<Rule Id="CA1400" Action="Warning" />
<Rule Id="CA1401" Action="Warning" />
<Rule Id="CA1402" Action="Warning" />
<Rule Id="CA1403" Action="Warning" />
<Rule Id="CA1404" Action="Warning" />
<Rule Id="CA1405" Action="Warning" />
<Rule Id="CA1406" Action="Warning" />
<Rule Id="CA1407" Action="Warning" />
<Rule Id="CA1408" Action="Warning" />
<Rule Id="CA1409" Action="Warning" />
<Rule Id="CA1410" Action="Warning" />
<Rule Id="CA1411" Action="Warning" />
<Rule Id="CA1412" Action="Warning" />
<Rule Id="CA1413" Action="Warning" />
<Rule Id="CA1414" Action="Warning" />
<Rule Id="CA1415" Action="Warning" />
<Rule Id="CA1500" Action="Warning" />
<Rule Id="CA1501" Action="Warning" />
<Rule Id="CA1502" Action="Warning" />
<Rule Id="CA1504" Action="Warning" />
<Rule Id="CA1505" Action="Warning" />
<Rule Id="CA1506" Action="Warning" />
<Rule Id="CA1600" Action="Warning" />
<Rule Id="CA1601" Action="Warning" />
<Rule Id="CA1700" Action="Warning" />
<Rule Id="CA1701" Action="Warning" />
<Rule Id="CA1702" Action="Warning" />
<Rule Id="CA1703" Action="Warning" />
<Rule Id="CA1704" Action="Warning" />
<Rule Id="CA1707" Action="Warning" />
<Rule Id="CA1708" Action="Warning" />
<Rule Id="CA1709" Action="Warning" />
<Rule Id="CA1710" Action="Warning" />
<Rule Id="CA1711" Action="Warning" />
<Rule Id="CA1712" Action="Warning" />
<Rule Id="CA1713" Action="Warning" />
<Rule Id="CA1714" Action="Warning" />
<Rule Id="CA1715" Action="Warning" />
<Rule Id="CA1716" Action="Warning" />
<Rule Id="CA1717" Action="Warning" />
<Rule Id="CA1719" Action="Warning" />
<Rule Id="CA1720" Action="Warning" />
<Rule Id="CA1721" Action="Warning" />
<Rule Id="CA1722" Action="Warning" />
<Rule Id="CA1724" Action="Warning" />
<Rule Id="CA1725" Action="Warning" />
<Rule Id="CA1726" Action="Warning" />
<Rule Id="CA1800" Action="Warning" />
<Rule Id="CA1801" Action="Warning" />
<Rule Id="CA1802" Action="Warning" />
<Rule Id="CA1804" Action="Warning" />
<Rule Id="CA1806" Action="Warning" />
<Rule Id="CA1809" Action="Warning" />
<Rule Id="CA1810" Action="Warning" />
<Rule Id="CA1811" Action="Warning" />
<Rule Id="CA1812" Action="Warning" />
<Rule Id="CA1813" Action="Warning" />
<Rule Id="CA1814" Action="Warning" />
<Rule Id="CA1815" Action="Warning" />
<Rule Id="CA1816" Action="Warning" />
<Rule Id="CA1819" Action="Warning" />
<Rule Id="CA1820" Action="Warning" />
<Rule Id="CA1821" Action="Warning" />
<Rule Id="CA1822" Action="Warning" />
<Rule Id="CA1823" Action="Warning" />
<Rule Id="CA1824" Action="Warning" />
<Rule Id="CA1900" Action="Warning" />
<Rule Id="CA1901" Action="Warning" />
<Rule Id="CA1903" Action="Warning" />
<Rule Id="CA2000" Action="Warning" />
<Rule Id="CA2001" Action="Warning" />
<Rule Id="CA2002" Action="Warning" />
<Rule Id="CA2003" Action="Warning" />
<Rule Id="CA2004" Action="Warning" />
<Rule Id="CA2006" Action="Warning" />
<Rule Id="CA2100" Action="Warning" />
<Rule Id="CA2101" Action="Warning" />
<Rule Id="CA2102" Action="Warning" />
<Rule Id="CA2103" Action="Warning" />
<Rule Id="CA2104" Action="Warning" />
<Rule Id="CA2105" Action="Warning" />
<Rule Id="CA2106" Action="Warning" />
<Rule Id="CA2107" Action="Warning" />
<Rule Id="CA2108" Action="Warning" />
<Rule Id="CA2109" Action="Warning" />
<Rule Id="CA2111" Action="Warning" />
<Rule Id="CA2112" Action="Warning" />
<Rule Id="CA2114" Action="Warning" />
<Rule Id="CA2115" Action="Warning" />
<Rule Id="CA2116" Action="Warning" />
<Rule Id="CA2117" Action="Warning" />
<Rule Id="CA2118" Action="Warning" />
<Rule Id="CA2119" Action="Warning" />
<Rule Id="CA2120" Action="Warning" />
<Rule Id="CA2121" Action="Warning" />
<Rule Id="CA2122" Action="Warning" />
<Rule Id="CA2123" Action="Warning" />
<Rule Id="CA2124" Action="Warning" />
<Rule Id="CA2126" Action="Warning" />
<Rule Id="CA2130" Action="Warning" />
<Rule Id="CA2131" Action="Warning" />
<Rule Id="CA2132" Action="Warning" />
<Rule Id="CA2133" Action="Warning" />
<Rule Id="CA2134" Action="Warning" />
<Rule Id="CA2135" Action="Warning" />
<Rule Id="CA2136" Action="Warning" />
<Rule Id="CA2137" Action="Warning" />
<Rule Id="CA2138" Action="Warning" />
<Rule Id="CA2139" Action="Warning" />
<Rule Id="CA2140" Action="Warning" />
<Rule Id="CA2141" Action="Warning" />
<Rule Id="CA2142" Action="Warning" />
<Rule Id="CA2143" Action="Warning" />
<Rule Id="CA2144" Action="Warning" />
<Rule Id="CA2145" Action="Warning" />
<Rule Id="CA2146" Action="Warning" />
<Rule Id="CA2147" Action="Warning" />
<Rule Id="CA2149" Action="Warning" />
<Rule Id="CA2151" Action="Warning" />
<Rule Id="CA2200" Action="Warning" />
<Rule Id="CA2201" Action="Warning" />
<Rule Id="CA2202" Action="Warning" />
<Rule Id="CA2204" Action="Warning" />
<Rule Id="CA2205" Action="Warning" />
<Rule Id="CA2207" Action="Warning" />
<Rule Id="CA2208" Action="Warning" />
<Rule Id="CA2210" Action="Warning" />
<Rule Id="CA2211" Action="Warning" />
<Rule Id="CA2212" Action="Warning" />
<Rule Id="CA2213" Action="Warning" />
<Rule Id="CA2214" Action="Warning" />
<Rule Id="CA2215" Action="Warning" />
<Rule Id="CA2216" Action="Warning" />
<Rule Id="CA2217" Action="Warning" />
<Rule Id="CA2218" Action="Warning" />
<Rule Id="CA2219" Action="Warning" />
<Rule Id="CA2220" Action="Warning" />
<Rule Id="CA2221" Action="Warning" />
<Rule Id="CA2222" Action="Warning" />
<Rule Id="CA2223" Action="Warning" />
<Rule Id="CA2224" Action="Warning" />
<Rule Id="CA2225" Action="Warning" />
<Rule Id="CA2226" Action="Warning" />
<Rule Id="CA2227" Action="Warning" />
<Rule Id="CA2228" Action="Warning" />
<Rule Id="CA2229" Action="Warning" />
<Rule Id="CA2230" Action="Warning" />
<Rule Id="CA2231" Action="Warning" />
<Rule Id="CA2232" Action="Warning" />
<Rule Id="CA2233" Action="Warning" />
<Rule Id="CA2234" Action="Warning" />
<Rule Id="CA2235" Action="Warning" />
<Rule Id="CA2236" Action="Warning" />
<Rule Id="CA2237" Action="Warning" />
<Rule Id="CA2238" Action="Warning" />
<Rule Id="CA2239" Action="Warning" />
<Rule Id="CA2240" Action="Warning" />
<Rule Id="CA2241" Action="Warning" />
<Rule Id="CA2242" Action="Warning" />
<Rule Id="CA2243" Action="Warning" />
<Rule Id="CA5122" Action="Warning" />
</Rules>
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
<Rule Id="IDE0008" Action="None" />
<Rule Id="IDE0008WithoutSuggestion" Action="None" />
</Rules>
<Rules AnalyzerId="Microsoft.NetCore.Analyzers" RuleNamespace="Microsoft.NetCore.Analyzers">
<Rule Id="CA1813" Action="Warning" />
</Rules>
<Rules AnalyzerId="Roslynator.CSharp.Analyzers" RuleNamespace="Roslynator.CSharp.Analyzers">
<Rule Id="RCS1010" Action="Warning" />
<Rule Id="RCS1177" Action="Warning" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1121" Action="None" />
<Rule Id="SA1633" Action="None" />
<Rule Id="SA1634" Action="None" />
<Rule Id="SA1635" Action="None" />
<Rule Id="SA1636" Action="None" />
<Rule Id="SA1637" Action="None" />
<Rule Id="SA1638" Action="None" />
<Rule Id="SA1640" Action="None" />
<Rule Id="SA1641" Action="None" />
</Rules>
</RuleSet>

View File

@ -1,128 +1,142 @@
namespace X10D namespace X10D
{ {
/// <summary> /// <summary>
/// Extension methods for <see cref="bool"/>. /// Extension methods for <see cref="bool" />.
/// </summary> /// </summary>
public static class BooleanExtensions public static class BooleanExtensions
{ {
/// <summary> /// <summary>
/// Performs logical AND on this <see cref="bool"/> and another <see cref="bool"/>. /// Performs logical AND on this <see cref="bool" /> and another <see cref="bool" />.
/// </summary> /// </summary>
/// <param name="value">The boolean.</param> /// <param name="value">The boolean.</param>
/// <param name="comparison">The boolean comparator.</param> /// <param name="comparison">The boolean comparator.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="value"/> AND <paramref name="comparison"/> /// <returns>
/// evaluate to <see langword="true"/>, or <see langword="false"/> otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="value" /> AND <paramref name="comparison" />
/// evaluate to <see langword="true" />, or <see langword="false" /> otherwise.
/// </returns>
public static bool And(this bool value, bool comparison) public static bool And(this bool value, bool comparison)
{ {
return value && comparison; return value && comparison;
} }
/// <summary> /// <summary>
/// Performs logical NAND on this <see cref="bool"/> and another <see cref="bool"/>. /// Performs logical NAND on this <see cref="bool" /> and another <see cref="bool" />.
/// </summary> /// </summary>
/// <param name="value">The boolean.</param> /// <param name="value">The boolean.</param>
/// <param name="comparison">The boolean comparator.</param> /// <param name="comparison">The boolean comparator.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="value"/> NAND <paramref name="comparison"/> /// <returns>
/// evaluate to <see langword="true"/>, or <see langword="false"/> otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="value" /> NAND <paramref name="comparison" />
/// evaluate to <see langword="true" />, or <see langword="false" /> otherwise.
/// </returns>
public static bool NAnd(this bool value, bool comparison) public static bool NAnd(this bool value, bool comparison)
{ {
return !(value && comparison); return !(value && comparison);
} }
/// <summary> /// <summary>
/// Performs logical NOR on this <see cref="bool"/> and another <see cref="bool"/>. /// Performs logical NOR on this <see cref="bool" /> and another <see cref="bool" />.
/// </summary> /// </summary>
/// <param name="value">The boolean.</param> /// <param name="value">The boolean.</param>
/// <param name="comparison">The boolean comparator.</param> /// <param name="comparison">The boolean comparator.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="value"/> NOR <paramref name="comparison"/> /// <returns>
/// evaluate to <see langword="true"/>, or <see langword="false"/> otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="value" /> NOR <paramref name="comparison" />
/// evaluate to <see langword="true" />, or <see langword="false" /> otherwise.
/// </returns>
public static bool NOr(this bool value, bool comparison) public static bool NOr(this bool value, bool comparison)
{ {
return !(value || comparison); return !(value || comparison);
} }
/// <summary> /// <summary>
/// Performs logical NOT on this <see cref="bool"/>. /// Performs logical NOT on this <see cref="bool" />.
/// </summary> /// </summary>
/// <param name="value">The boolean.</param> /// <param name="value">The boolean.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="value"/> is <see langword="false"/>, /// <returns>
/// or <see langword="false"/> otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="value" /> is <see langword="false" />,
/// or <see langword="false" /> otherwise.
/// </returns>
public static bool Not(this bool value) public static bool Not(this bool value)
{ {
return !value; return !value;
} }
/// <summary> /// <summary>
/// Performs logical OR on this <see cref="bool"/> and another <see cref="bool"/>. /// Performs logical OR on this <see cref="bool" /> and another <see cref="bool" />.
/// </summary> /// </summary>
/// <param name="value">The boolean.</param> /// <param name="value">The boolean.</param>
/// <param name="comparison">The boolean comparator.</param> /// <param name="comparison">The boolean comparator.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="value"/> OR <paramref name="comparison"/> /// <returns>
/// evaluate to <see langword="true"/>, or <see langword="false"/> otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="value" /> OR <paramref name="comparison" />
/// evaluate to <see langword="true" />, or <see langword="false" /> otherwise.
/// </returns>
public static bool Or(this bool value, bool comparison) public static bool Or(this bool value, bool comparison)
{ {
return value || comparison; return value || comparison;
} }
/// <summary> /// <summary>
/// Gets the value of this boolean as represented by <see cref="byte"/>. /// Gets the value of this boolean as represented by <see cref="byte" />.
/// </summary> /// </summary>
/// <param name="value">The boolean.</param> /// <param name="value">The boolean.</param>
/// <returns>Returns 1 if <paramref name="value"/> is <see langword="true"/>, or 0 otherwise.</returns> /// <returns>Returns 1 if <paramref name="value" /> is <see langword="true" />, or 0 otherwise.</returns>
public static byte ToByte(this bool value) public static byte ToByte(this bool value)
{ {
return (byte)value.ToInt32(); return (byte)value.ToInt32();
} }
/// <summary> /// <summary>
/// Gets the value of this boolean as represented by <see cref="short"/>. /// Gets the value of this boolean as represented by <see cref="short" />.
/// </summary> /// </summary>
/// <param name="value">The boolean.</param> /// <param name="value">The boolean.</param>
/// <returns>Returns 1 if <paramref name="value"/> is <see langword="true"/>, or 0 otherwise.</returns> /// <returns>Returns 1 if <paramref name="value" /> is <see langword="true" />, or 0 otherwise.</returns>
public static short ToInt16(this bool value) public static short ToInt16(this bool value)
{ {
return (short)value.ToInt32(); return (short)value.ToInt32();
} }
/// <summary> /// <summary>
/// Gets the value of this boolean as represented by <see cref="int"/>. /// Gets the value of this boolean as represented by <see cref="int" />.
/// </summary> /// </summary>
/// <param name="value">The boolean.</param> /// <param name="value">The boolean.</param>
/// <returns>Returns 1 if <paramref name="value"/> is <see langword="true"/>, or 0 otherwise.</returns> /// <returns>Returns 1 if <paramref name="value" /> is <see langword="true" />, or 0 otherwise.</returns>
public static int ToInt32(this bool value) public static int ToInt32(this bool value)
{ {
return value ? 1 : 0; return value ? 1 : 0;
} }
/// <summary> /// <summary>
/// Gets the value of this boolean as represented by <see cref="long"/>. /// Gets the value of this boolean as represented by <see cref="long" />.
/// </summary> /// </summary>
/// <param name="value">The boolean.</param> /// <param name="value">The boolean.</param>
/// <returns>Returns 1 if <paramref name="value"/> is <see langword="true"/>, 0 otherwise.</returns> /// <returns>Returns 1 if <paramref name="value" /> is <see langword="true" />, 0 otherwise.</returns>
public static long ToInt64(this bool value) public static long ToInt64(this bool value)
{ {
return value.ToInt32(); return value.ToInt32();
} }
/// <summary> /// <summary>
/// Performs logical XNOR on this <see cref="bool"/> and another <see cref="bool"/>. /// Performs logical XNOR on this <see cref="bool" /> and another <see cref="bool" />.
/// </summary> /// </summary>
/// <param name="value">The boolean.</param> /// <param name="value">The boolean.</param>
/// <param name="comparison">The boolean comparator.</param> /// <param name="comparison">The boolean comparator.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="value"/> XNOR <paramref name="comparison"/> /// <returns>
/// evaluate to <see langword="true"/>, or <see langword="false"/> otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="value" /> XNOR <paramref name="comparison" />
/// evaluate to <see langword="true" />, or <see langword="false" /> otherwise.
/// </returns>
public static bool XNOr(this bool value, bool comparison) public static bool XNOr(this bool value, bool comparison)
{ {
return !(value ^ comparison); return !(value ^ comparison);
} }
/// <summary> /// <summary>
/// Performs logical XOR on this <see cref="bool"/> and another <see cref="bool"/>. /// Performs logical XOR on this <see cref="bool" /> and another <see cref="bool" />.
/// </summary> /// </summary>
/// <param name="value">The boolean.</param> /// <param name="value">The boolean.</param>
/// <param name="comparison">The boolean comparator.</param> /// <param name="comparison">The boolean comparator.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="value"/> XOR <paramref name="comparison"/> /// <returns>
/// evaluate to <see langword="true"/>, or <see langword="false"/> otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="value" /> XOR <paramref name="comparison" />
/// evaluate to <see langword="true" />, or <see langword="false" /> otherwise.
/// </returns>
public static bool XOr(this bool value, bool comparison) public static bool XOr(this bool value, bool comparison)
{ {
return value ^ comparison; return value ^ comparison;

View File

@ -6,101 +6,68 @@
using System.Text; using System.Text;
/// <summary> /// <summary>
/// Extension methods for <see cref="byte"/>. /// Extension methods for <see cref="byte" />.
/// </summary> /// </summary>
public static class ByteExtensions public static class ByteExtensions
{ {
/// <summary> /// <summary>
/// Gets a <see cref="string"/> literally representing the raw values in the <see cref="byte"/>[]. /// Gets a <see cref="string" /> literally representing the raw values in the <see cref="byte" />[].
/// </summary> /// </summary>
/// <param name="bytes">The bytes to get.</param> /// <param name="bytes">The bytes to get.</param>
/// <returns>Returns a <see cref="string"/>.</returns> /// <returns>Returns a <see cref="string" />.</returns>
public static string AsString(this IEnumerable<byte> bytes) public static string AsString(this IEnumerable<byte> bytes)
{ {
return BitConverter.ToString(bytes.ToArray()); return BitConverter.ToString(bytes.ToArray());
} }
/// <summary> /// <summary>
/// Converts the <see cref="byte"/>[] to an <see cref="short"/>. /// Converts the <see cref="byte" />[] to an <see cref="short" />.
/// </summary> /// </summary>
/// <param name="bytes">The bytes to convert.</param> /// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="short"/>.</returns> /// <returns>Returns an <see cref="short" />.</returns>
public static short GetInt16(this IEnumerable<byte> bytes) public static short GetInt16(this IEnumerable<byte> bytes)
{ {
return BitConverter.ToInt16(bytes.ToArray(), 0); return BitConverter.ToInt16(bytes.ToArray(), 0);
} }
/// <summary> /// <summary>
/// Converts the <see cref="byte"/>[] to an <see cref="int"/>. /// Converts the <see cref="byte" />[] to an <see cref="int" />.
/// </summary> /// </summary>
/// <param name="bytes">The bytes to convert.</param> /// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="int"/>.</returns> /// <returns>Returns an <see cref="int" />.</returns>
public static int GetInt32(this IEnumerable<byte> bytes) public static int GetInt32(this IEnumerable<byte> bytes)
{ {
return BitConverter.ToInt32(bytes.ToArray(), 0); return BitConverter.ToInt32(bytes.ToArray(), 0);
} }
/// <summary> /// <summary>
/// Converts the <see cref="byte"/>[] to an <see cref="long"/>. /// Converts the <see cref="byte" />[] to an <see cref="long" />.
/// </summary> /// </summary>
/// <param name="bytes">The bytes to convert.</param> /// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="long"/>.</returns> /// <returns>Returns an <see cref="long" />.</returns>
public static long GetInt64(this IEnumerable<byte> bytes) public static long GetInt64(this IEnumerable<byte> bytes)
{ {
return BitConverter.ToInt64(bytes.ToArray(), 0); return BitConverter.ToInt64(bytes.ToArray(), 0);
} }
/// <summary> /// <summary>
/// Converts the <see cref="byte"/>[] to a <see cref="ushort"/>. /// Gets a <see cref="string" /> representing the value the <see cref="byte" />[] with
/// <see cref="Encoding.UTF8" /> encoding.
/// </summary> /// </summary>
/// <param name="bytes">The bytes to convert.</param> /// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="ushort"/>.</returns> /// <returns>Returns a <see cref="string" />.</returns>
[CLSCompliant(false)]
public static ushort GetUInt16(this IEnumerable<byte> bytes)
{
return BitConverter.ToUInt16(bytes.ToArray(), 0);
}
/// <summary>
/// Converts the <see cref="byte"/>[] to an <see cref="uint"/>.
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="uint"/>.</returns>
[CLSCompliant(false)]
public static uint GetUInt32(this IEnumerable<byte> bytes)
{
return BitConverter.ToUInt32(bytes.ToArray(), 0);
}
/// <summary>
/// Converts the <see cref="byte"/>[] to an <see cref="ulong"/>.
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="ulong"/>.</returns>
[CLSCompliant(false)]
public static ulong GetUInt64(this IEnumerable<byte> bytes)
{
return BitConverter.ToUInt64(bytes.ToArray(), 0);
}
/// <summary>
/// Gets a <see cref="string"/> representing the value the <see cref="byte"/>[] with
/// <see cref="Encoding.UTF8"/> encoding.
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns a <see cref="string"/>.</returns>
public static string GetString(this IEnumerable<byte> bytes) public static string GetString(this IEnumerable<byte> bytes)
{ {
return bytes.GetString(Encoding.UTF8); return bytes.GetString(Encoding.UTF8);
} }
/// <summary> /// <summary>
/// Gets a <see cref="string"/> representing the value the <see cref="byte"/>[] with the provided encoding. /// Gets a <see cref="string" /> representing the value the <see cref="byte" />[] with the provided encoding.
/// </summary> /// </summary>
/// <param name="bytes">The bytes to convert.</param> /// <param name="bytes">The bytes to convert.</param>
/// <param name="encoding">The encoding to use.</param> /// <param name="encoding">The encoding to use.</param>
/// <returns>Returns a <see cref="string"/>.</returns> /// <returns>Returns a <see cref="string" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="encoding"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="encoding" /> is <see langword="null" />.</exception>
public static string GetString(this IEnumerable<byte> bytes, Encoding encoding) public static string GetString(this IEnumerable<byte> bytes, Encoding encoding)
{ {
if (encoding is null) if (encoding is null)
@ -112,5 +79,38 @@
var array = bytes.ToArray(); var array = bytes.ToArray();
return encoding.GetString(array, 0, array.Length); return encoding.GetString(array, 0, array.Length);
} }
/// <summary>
/// Converts the <see cref="byte" />[] to a <see cref="ushort" />.
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="ushort" />.</returns>
[CLSCompliant(false)]
public static ushort GetUInt16(this IEnumerable<byte> bytes)
{
return BitConverter.ToUInt16(bytes.ToArray(), 0);
}
/// <summary>
/// Converts the <see cref="byte" />[] to an <see cref="uint" />.
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="uint" />.</returns>
[CLSCompliant(false)]
public static uint GetUInt32(this IEnumerable<byte> bytes)
{
return BitConverter.ToUInt32(bytes.ToArray(), 0);
}
/// <summary>
/// Converts the <see cref="byte" />[] to an <see cref="ulong" />.
/// </summary>
/// <param name="bytes">The bytes to convert.</param>
/// <returns>Returns an <see cref="ulong" />.</returns>
[CLSCompliant(false)]
public static ulong GetUInt64(this IEnumerable<byte> bytes)
{
return BitConverter.ToUInt64(bytes.ToArray(), 0);
}
} }
} }

View File

@ -6,29 +6,29 @@
using System.Text; using System.Text;
/// <summary> /// <summary>
/// Extension methods for <see cref="char"/>. /// Extension methods for <see cref="char" />.
/// </summary> /// </summary>
public static class CharExtensions public static class CharExtensions
{ {
/// <summary> /// <summary>
/// Generates a new random string by filling it with characters found in <see cref="chars"/>. /// Generates a new random string by filling it with characters found in <see cref="chars" />.
/// </summary> /// </summary>
/// <param name="chars">The character set.</param> /// <param name="chars">The character set.</param>
/// <param name="length">The length of the string to generate.</param> /// <param name="length">The length of the string to generate.</param>
/// <returns>Returns a <see cref="string"/> containing <paramref name="length"/> characters.</returns> /// <returns>Returns a <see cref="string" /> containing <paramref name="length" /> characters.</returns>
public static string Random(this char[] chars, int length) public static string Random(this char[] chars, int length)
{ {
return chars.Random(length, RandomExtensions.Random); return chars.Random(length, RandomExtensions.Random);
} }
/// <summary> /// <summary>
/// Generates a new random string by filling it with characters found in <see cref="chars"/>. /// Generates a new random string by filling it with characters found in <see cref="chars" />.
/// </summary> /// </summary>
/// <param name="chars">The character set.</param> /// <param name="chars">The character set.</param>
/// <param name="length">The length of the string to generate.</param> /// <param name="length">The length of the string to generate.</param>
/// <param name="random">The <see cref="System.Random"/> instance.</param> /// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <returns>Returns a <see cref="string"/> containing <paramref name="length"/> characters.</returns> /// <returns>Returns a <see cref="string" /> containing <paramref name="length" /> characters.</returns>
/// <exception cref="ArgumentNullException"><paramref name="random"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
public static string Random(this char[] chars, int length, Random random) public static string Random(this char[] chars, int length, Random random)
{ {
if (chars is null) if (chars is null)
@ -51,23 +51,23 @@
} }
/// <summary> /// <summary>
/// Generates a new random string by filling it with characters found in <see cref="chars"/>. /// Generates a new random string by filling it with characters found in <see cref="chars" />.
/// </summary> /// </summary>
/// <param name="chars">The character set.</param> /// <param name="chars">The character set.</param>
/// <param name="length">The length of the string to generate.</param> /// <param name="length">The length of the string to generate.</param>
/// <returns>Returns a <see cref="string"/> containing <paramref name="length"/> characters.</returns> /// <returns>Returns a <see cref="string" /> containing <paramref name="length" /> characters.</returns>
public static string Random(this IEnumerable<char> chars, int length) public static string Random(this IEnumerable<char> chars, int length)
{ {
return chars.Random(length, RandomExtensions.Random); return chars.Random(length, RandomExtensions.Random);
} }
/// <summary> /// <summary>
/// Generates a new random string by filling it with characters found in <see cref="chars"/>. /// Generates a new random string by filling it with characters found in <see cref="chars" />.
/// </summary> /// </summary>
/// <param name="chars">The character set.</param> /// <param name="chars">The character set.</param>
/// <param name="length">The length of the string to generate.</param> /// <param name="length">The length of the string to generate.</param>
/// <param name="random">The <see cref="System.Random"/> instance.</param> /// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <returns>Returns a <see cref="string"/> containing <paramref name="length"/> characters.</returns> /// <returns>Returns a <see cref="string" /> containing <paramref name="length" /> characters.</returns>
public static string Random(this IEnumerable<char> chars, int length, Random random) public static string Random(this IEnumerable<char> chars, int length, Random random)
{ {
return chars.ToArray().Random(length, random); return chars.ToArray().Random(length, random);
@ -78,8 +78,10 @@
/// </summary> /// </summary>
/// <param name="c">The character to repeat.</param> /// <param name="c">The character to repeat.</param>
/// <param name="count">The repeat count.</param> /// <param name="count">The repeat count.</param>
/// <returns>Returns a <see cref="string"/> whose value is <paramref name="c"/> repeated /// <returns>
/// <paramref name="count"/> times.</returns> /// Returns a <see cref="string" /> whose value is <paramref name="c" /> repeated
/// <paramref name="count" /> times.
/// </returns>
public static string Repeat(this char c, int count) public static string Repeat(this char c, int count)
{ {
return new string(c, count); return new string(c, count);

View File

@ -3,19 +3,21 @@
using System; using System;
/// <summary> /// <summary>
/// Extension methods for <see cref="IComparable"/>. /// Extension methods for <see cref="IComparable" />.
/// </summary> /// </summary>
public static class ComparableExtensions public static class ComparableExtensions
{ {
/// <summary> /// <summary>
/// Determines if <paramref name="actual"/> is between <paramref name="lower"/> and <paramref name="upper"/>. /// Determines if <paramref name="actual" /> is between <paramref name="lower" /> and <paramref name="upper" />.
/// </summary> /// </summary>
/// <typeparam name="T">The comparable type.</typeparam> /// <typeparam name="T">The comparable type.</typeparam>
/// <param name="actual">The value to compare.</param> /// <param name="actual">The value to compare.</param>
/// <param name="lower">The exclusive lower bound.</param> /// <param name="lower">The exclusive lower bound.</param>
/// <param name="upper">The exclusive upper bound.</param> /// <param name="upper">The exclusive upper bound.</param>
/// <returns>Returns <see langword="true"/> if the value is between the bounds, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if the value is between the bounds, <see langword="false" />
/// otherwise.
/// </returns>
public static bool Between<T>(this T actual, T lower, T upper) public static bool Between<T>(this T actual, T lower, T upper)
where T : IComparable<T> where T : IComparable<T>
{ {

View File

@ -3,7 +3,7 @@
using System; using System;
/// <summary> /// <summary>
/// Extension methods for <see cref="IConvertible"/>. /// Extension methods for <see cref="IConvertible" />.
/// </summary> /// </summary>
public static class ConvertibleExtensions public static class ConvertibleExtensions
{ {
@ -13,10 +13,12 @@
/// <typeparam name="T">The type to convert to.</typeparam> /// <typeparam name="T">The type to convert to.</typeparam>
/// <param name="value">The object to convert.</param> /// <param name="value">The object to convert.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param> /// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>Returns the value converted to <see cref="T"/>.</returns> /// <returns>Returns the value converted to <see cref="T" />.</returns>
/// <exception cref="InvalidCastException">This conversion is not supported. /// <exception cref="InvalidCastException">
/// This conversion is not supported.
/// -or- /// -or-
/// <paramref name="value"/> is <see langword="null"/> and <typeparamref name="T"/> is a value type.</exception> /// <paramref name="value" /> is <see langword="null" /> and <typeparamref name="T" /> is a value type.
/// </exception>
[CLSCompliant(false)] [CLSCompliant(false)]
public static T To<T>(this IConvertible value, IFormatProvider provider = null) public static T To<T>(this IConvertible value, IFormatProvider provider = null)
{ {
@ -34,7 +36,7 @@
/// <typeparam name="T">The type to convert to.</typeparam> /// <typeparam name="T">The type to convert to.</typeparam>
/// <param name="value">The object to convert.</param> /// <param name="value">The object to convert.</param>
/// <param name="provider">The format provider.</param> /// <param name="provider">The format provider.</param>
/// <returns>Returns the value converted to <see cref="T"/>.</returns> /// <returns>Returns the value converted to <see cref="T" />.</returns>
/// <exception cref="InvalidCastException">This conversion is not supported.</exception> /// <exception cref="InvalidCastException">This conversion is not supported.</exception>
[CLSCompliant(false)] [CLSCompliant(false)]
public static T ToOrDefault<T>(this IConvertible value, IFormatProvider provider = null) public static T ToOrDefault<T>(this IConvertible value, IFormatProvider provider = null)
@ -49,7 +51,7 @@
/// <param name="value">The object to convert.</param> /// <param name="value">The object to convert.</param>
/// <param name="newObj">The parameter where the result should be sent.</param> /// <param name="newObj">The parameter where the result should be sent.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param> /// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>Returns <see langword="true"/> on success, <see langword="true"/> on failure.</returns> /// <returns>Returns <see langword="true" /> on success, <see langword="true" /> on failure.</returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool ToOrDefault<T>(this IConvertible value, out T newObj, IFormatProvider provider = null) public static bool ToOrDefault<T>(this IConvertible value, out T newObj, IFormatProvider provider = null)
{ {
@ -71,6 +73,35 @@
} }
} }
/// <summary>
/// Converts the object to another type, returning <see langword="null" /> on failure.
/// </summary>
/// <typeparam name="T">The type to convert to.</typeparam>
/// <param name="value">The object to convert.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>Returns a <see cref="T" /> or <see langword="null" />.</returns>
[CLSCompliant(false)]
public static T ToOrNull<T>(this IConvertible value, IFormatProvider provider = null)
where T : class
{
return value.ToOrNull(out T v, provider) ? v : null;
}
/// <summary>
/// Converts the object to another type, returning <see langword="null" /> on failure.
/// </summary>
/// <typeparam name="T">The type to convert to.</typeparam>
/// <param name="value">The object to convert.</param>
/// <param name="newObj">The parameter where the result should be sent.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>Returns a <see cref="T" /> or <see langword="null" />.</returns>
[CLSCompliant(false)]
public static bool ToOrNull<T>(this IConvertible value, out T newObj, IFormatProvider provider = null)
where T : class
{
return ToOrOther(value, out newObj, null, provider);
}
/// <summary> /// <summary>
/// Converts the object to another type, returning a different value on failure. /// Converts the object to another type, returning a different value on failure.
/// </summary> /// </summary>
@ -78,7 +109,7 @@
/// <param name="value">The object to convert.</param> /// <param name="value">The object to convert.</param>
/// <param name="other">The backup value.</param> /// <param name="other">The backup value.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param> /// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>Returns the value converted to <see cref="T"/>.</returns> /// <returns>Returns the value converted to <see cref="T" />.</returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static T ToOrOther<T>(this IConvertible value, T other, IFormatProvider provider = null) public static T ToOrOther<T>(this IConvertible value, T other, IFormatProvider provider = null)
{ {
@ -105,7 +136,7 @@
/// <param name="newObj">The parameter where the result should be sent.</param> /// <param name="newObj">The parameter where the result should be sent.</param>
/// <param name="other">The backup value.</param> /// <param name="other">The backup value.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param> /// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>Returns <see langword="true"/> on success, <see langword="true"/> on failure.</returns> /// <returns>Returns <see langword="true" /> on success, <see langword="true" /> on failure.</returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool ToOrOther<T>(this IConvertible value, out T newObj, T other, IFormatProvider provider = null) public static bool ToOrOther<T>(this IConvertible value, out T newObj, T other, IFormatProvider provider = null)
{ {
@ -126,34 +157,5 @@
return false; return false;
} }
} }
/// <summary>
/// Converts the object to another type, returning <see langword="null"/> on failure.
/// </summary>
/// <typeparam name="T">The type to convert to.</typeparam>
/// <param name="value">The object to convert.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>Returns a <see cref="T"/> or <see langword="null"/>.</returns>
[CLSCompliant(false)]
public static T ToOrNull<T>(this IConvertible value, IFormatProvider provider = null)
where T : class
{
return value.ToOrNull(out T v, provider) ? v : null;
}
/// <summary>
/// Converts the object to another type, returning <see langword="null"/> on failure.
/// </summary>
/// <typeparam name="T">The type to convert to.</typeparam>
/// <param name="value">The object to convert.</param>
/// <param name="newObj">The parameter where the result should be sent.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>Returns a <see cref="T"/> or <see langword="null"/>.</returns>
[CLSCompliant(false)]
public static bool ToOrNull<T>(this IConvertible value, out T newObj, IFormatProvider provider = null)
where T : class
{
return ToOrOther(value, out newObj, null, provider);
}
} }
} }

View File

@ -3,7 +3,7 @@
using System; using System;
/// <summary> /// <summary>
/// Extension methods for <see cref="DateTime"/>. /// Extension methods for <see cref="DateTime" />.
/// </summary> /// </summary>
public static class DateTimeExtensions public static class DateTimeExtensions
{ {
@ -11,7 +11,7 @@
/// 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.
/// </summary> /// </summary>
/// <param name="date">The date from which to start.</param> /// <param name="date">The date from which to start.</param>
/// <returns>Returns the number of years since <paramref name="date"/> as of today.</returns> /// <returns>Returns the number of years since <paramref name="date" /> as of today.</returns>
public static int Age(this DateTime date) public static int Age(this DateTime date)
{ {
return date.Age(DateTime.Today); return date.Age(DateTime.Today);
@ -22,8 +22,10 @@
/// </summary> /// </summary>
/// <param name="date">The date from which to start.</param> /// <param name="date">The date from which to start.</param>
/// <param name="asOf">The date at which to stop counting.</param> /// <param name="asOf">The date at which to stop counting.</param>
/// <returns>Returns the integer number of years since <paramref name="date"/> as of /// <returns>
/// <paramref name="asOf"/>.</returns> /// Returns the integer number of years since <paramref name="date" /> as of
/// <paramref name="asOf" />.
/// </returns>
public static int Age(this DateTime date, DateTime asOf) public static int Age(this DateTime date, DateTime asOf)
{ {
return (int)(((asOf.Date - TimeSpan.FromDays(1) - date.Date).TotalDays + 1) / 365.2425); return (int)(((asOf.Date - TimeSpan.FromDays(1) - date.Date).TotalDays + 1) / 365.2425);
@ -34,10 +36,10 @@
/// </summary> /// </summary>
/// <param name="current">The current day.</param> /// <param name="current">The current day.</param>
/// <param name="dayOfWeek">The current day of week.</param> /// <param name="dayOfWeek">The current day of week.</param>
/// <returns>Returns a date representing the first occurence of <paramref name="dayOfWeek"/>.</returns> /// <returns>Returns a date representing the first occurence of <paramref name="dayOfWeek" />.</returns>
public static DateTime First(this DateTime current, DayOfWeek dayOfWeek) public static DateTime First(this DateTime current, DayOfWeek dayOfWeek)
{ {
DateTime first = current.FirstDayOfMonth(); var first = current.FirstDayOfMonth();
if (first.DayOfWeek != dayOfWeek) if (first.DayOfWeek != dayOfWeek)
{ {
@ -48,7 +50,7 @@
} }
/// <summary> /// <summary>
/// Gets a <see cref="DateTime"/> representing the first day in the current month. /// Gets a <see cref="DateTime" /> representing the first day in the current month.
/// </summary> /// </summary>
/// <param name="current">The current date.</param> /// <param name="current">The current date.</param>
/// <returns>Returns a date representing the first day of the month>.</returns> /// <returns>Returns a date representing the first day of the month>.</returns>
@ -58,7 +60,24 @@
} }
/// <summary> /// <summary>
/// Gets a <see cref="DateTime"/> representing the last day in the current month. /// Gets a <see cref="DateTime" /> representing the last specified day in the current month.
/// </summary>
/// <param name="current">The current date.</param>
/// <param name="dayOfWeek">The current day of week.</param>
/// <returns>Returns a date representing the final occurence of <paramref name="dayOfWeek" />.</returns>
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);
}
/// <summary>
/// Gets a <see cref="DateTime" /> representing the last day in the current month.
/// </summary> /// </summary>
/// <param name="current">The current date.</param> /// <param name="current">The current date.</param>
/// <returns>Returns a date representing the last day of the month>.</returns> /// <returns>Returns a date representing the last day of the month>.</returns>
@ -69,29 +88,12 @@
} }
/// <summary> /// <summary>
/// Gets a <see cref="DateTime"/> representing the last specified day in the current month. /// Gets a <see cref="DateTime" /> representing the first date following the current date which falls on the
/// </summary>
/// <param name="current">The current date.</param>
/// <param name="dayOfWeek">The current day of week.</param>
/// <returns>Returns a date representing the final occurence of <paramref name="dayOfWeek"/>.</returns>
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);
}
/// <summary>
/// Gets a <see cref="DateTime"/> representing the first date following the current date which falls on the
/// given day of the week. /// given day of the week.
/// </summary> /// </summary>
/// <param name="current">The current date.</param> /// <param name="current">The current date.</param>
/// <param name="dayOfWeek">The day of week for the next date to get.</param> /// <param name="dayOfWeek">The day of week for the next date to get.</param>
/// <returns>Returns a date representing the next occurence of <paramref name="dayOfWeek"/>.</returns> /// <returns>Returns a date representing the next occurence of <paramref name="dayOfWeek" />.</returns>
public static DateTime Next(this DateTime current, DayOfWeek dayOfWeek) public static DateTime Next(this DateTime current, DayOfWeek dayOfWeek)
{ {
var offsetDays = dayOfWeek - current.DayOfWeek; var offsetDays = dayOfWeek - current.DayOfWeek;
@ -105,12 +107,14 @@
} }
/// <summary> /// <summary>
/// Converts the <see cref="DateTime"/> to a Unix timestamp. /// Converts the <see cref="DateTime" /> to a Unix timestamp.
/// </summary> /// </summary>
/// <param name="time">The <see cref="DateTime"/> instance.</param> /// <param name="time">The <see cref="DateTime" /> instance.</param>
/// <param name="useMillis">Optional. Whether or not the return value should be represented as milliseconds. /// <param name="useMillis">
/// Defaults to <see langword="false"/>.</param> /// Optional. Whether or not the return value should be represented as milliseconds.
/// <returns>Returns a Unix timestamp representing the provided <see cref="DateTime"/>.</returns> /// Defaults to <see langword="false" />.
/// </param>
/// <returns>Returns a Unix timestamp representing the provided <see cref="DateTime" />.</returns>
public static long ToUnixTimeStamp(this DateTime time, bool useMillis = false) public static long ToUnixTimeStamp(this DateTime time, bool useMillis = false)
{ {
DateTimeOffset offset = time; DateTimeOffset offset = time;

View File

@ -6,17 +6,17 @@
using System.Web; using System.Web;
/// <summary> /// <summary>
/// A set of extension methods for <see cref="Dictionary{TKey,TValue}"/>. /// A set of extension methods for <see cref="Dictionary{TKey,TValue}" />.
/// </summary> /// </summary>
public static class DictionaryExtensions public static class DictionaryExtensions
{ {
/// <summary> /// <summary>
/// Converts a <see cref="IReadOnlyDictionary{T1,T2}"/> to an object-relational-safe connection string. /// Converts a <see cref="IReadOnlyDictionary{T1,T2}" /> to an object-relational-safe connection string.
/// </summary> /// </summary>
/// <typeparam name="T1">The key type.</typeparam> /// <typeparam name="T1">The key type.</typeparam>
/// <typeparam name="T2">The value type.</typeparam> /// <typeparam name="T2">The value type.</typeparam>
/// <param name="dictionary">The dictionary.</param> /// <param name="dictionary">The dictionary.</param>
/// <returns>Returns a <see cref="string"/> representing the dictionary as a key=value; set.</returns> /// <returns>Returns a <see cref="string" /> representing the dictionary as a key=value; set.</returns>
public static string ToConnectionString<T1, T2>(this IReadOnlyDictionary<T1, T2> dictionary) public static string ToConnectionString<T1, T2>(this IReadOnlyDictionary<T1, T2> dictionary)
{ {
static string SanitizeValue<T>(T value) static string SanitizeValue<T>(T value)
@ -27,41 +27,41 @@
: value.ToString(); : value.ToString();
} }
IEnumerable<string> strings = dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value)}"); var strings = dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value)}");
return string.Join(";", strings); return string.Join(";", strings);
} }
/// <summary> /// <summary>
/// Converts a <see cref="IDictionary{T1,T2}"/> to an object-relational-safe connection string. /// Converts a <see cref="IDictionary{T1,T2}" /> to an object-relational-safe connection string.
/// </summary> /// </summary>
/// <typeparam name="T1">The key type.</typeparam> /// <typeparam name="T1">The key type.</typeparam>
/// <typeparam name="T2">The value type.</typeparam> /// <typeparam name="T2">The value type.</typeparam>
/// <param name="dictionary">The dictionary.</param> /// <param name="dictionary">The dictionary.</param>
/// <returns>Returns a <see cref="string"/> representing the dictionary as a key=value; set.</returns> /// <returns>Returns a <see cref="string" /> representing the dictionary as a key=value; set.</returns>
public static string ToConnectionString<T1, T2>(this IDictionary<T1, T2> dictionary) public static string ToConnectionString<T1, T2>(this IDictionary<T1, T2> dictionary)
{ {
return ((IReadOnlyDictionary<T1, T2>)dictionary).ToConnectionString(); return ((IReadOnlyDictionary<T1, T2>)dictionary).ToConnectionString();
} }
/// <summary> /// <summary>
/// Converts a <see cref="Dictionary{T1,T2}"/> to an object-relational-safe connection string. /// Converts a <see cref="Dictionary{T1,T2}" /> to an object-relational-safe connection string.
/// </summary> /// </summary>
/// <typeparam name="T1">The key type.</typeparam> /// <typeparam name="T1">The key type.</typeparam>
/// <typeparam name="T2">The value type.</typeparam> /// <typeparam name="T2">The value type.</typeparam>
/// <param name="dictionary">The dictionary.</param> /// <param name="dictionary">The dictionary.</param>
/// <returns>Returns a <see cref="string"/> representing the dictionary as a key=value; set.</returns> /// <returns>Returns a <see cref="string" /> representing the dictionary as a key=value; set.</returns>
public static string ToConnectionString<T1, T2>(this Dictionary<T1, T2> dictionary) public static string ToConnectionString<T1, T2>(this Dictionary<T1, T2> dictionary)
{ {
return ((IReadOnlyDictionary<T1, T2>)dictionary).ToConnectionString(); return ((IReadOnlyDictionary<T1, T2>)dictionary).ToConnectionString();
} }
/// <summary> /// <summary>
/// Converts an <see cref="IReadOnlyDictionary{T1,T2}"/> to a HTTP GET parameter string. /// Converts an <see cref="IReadOnlyDictionary{T1,T2}" /> to a HTTP GET parameter string.
/// </summary> /// </summary>
/// <typeparam name="T1">The key type.</typeparam> /// <typeparam name="T1">The key type.</typeparam>
/// <typeparam name="T2">The value type.</typeparam> /// <typeparam name="T2">The value type.</typeparam>
/// <param name="dictionary">The dictionary.</param> /// <param name="dictionary">The dictionary.</param>
/// <returns>Returns a <see cref="string"/> representing the dictionary as a key=value& set.</returns> /// <returns>Returns a <see cref="string" /> representing the dictionary as a key=value& set.</returns>
public static string ToGetParameters<T1, T2>(this IReadOnlyDictionary<T1, T2> dictionary) public static string ToGetParameters<T1, T2>(this IReadOnlyDictionary<T1, T2> dictionary)
{ {
static string Sanitize(KeyValuePair<T1, T2> kvp) static string Sanitize(KeyValuePair<T1, T2> kvp)
@ -75,24 +75,24 @@
} }
/// <summary> /// <summary>
/// Converts an <see cref="IDictionary{T1,T2}"/> to a HTTP GET parameter string. /// Converts an <see cref="IDictionary{T1,T2}" /> to a HTTP GET parameter string.
/// </summary> /// </summary>
/// <typeparam name="T1">The key type.</typeparam> /// <typeparam name="T1">The key type.</typeparam>
/// <typeparam name="T2">The value type.</typeparam> /// <typeparam name="T2">The value type.</typeparam>
/// <param name="dictionary">The dictionary.</param> /// <param name="dictionary">The dictionary.</param>
/// <returns>Returns a <see cref="string"/> representing the dictionary as a key=value& set.</returns> /// <returns>Returns a <see cref="string" /> representing the dictionary as a key=value& set.</returns>
public static string ToGetParameters<T1, T2>(this IDictionary<T1, T2> dictionary) public static string ToGetParameters<T1, T2>(this IDictionary<T1, T2> dictionary)
{ {
return ((IReadOnlyDictionary<T1, T2>)dictionary).ToGetParameters(); return ((IReadOnlyDictionary<T1, T2>)dictionary).ToGetParameters();
} }
/// <summary> /// <summary>
/// Converts a <see cref="Dictionary{T1,T2}"/> to a HTTP GET parameter string. /// Converts a <see cref="Dictionary{T1,T2}" /> to a HTTP GET parameter string.
/// </summary> /// </summary>
/// <typeparam name="T1">The key type.</typeparam> /// <typeparam name="T1">The key type.</typeparam>
/// <typeparam name="T2">The value type.</typeparam> /// <typeparam name="T2">The value type.</typeparam>
/// <param name="dictionary">The dictionary.</param> /// <param name="dictionary">The dictionary.</param>
/// <returns>Returns a <see cref="string"/> representing the dictionary as a key=value& set.</returns> /// <returns>Returns a <see cref="string" /> representing the dictionary as a key=value& set.</returns>
public static string ToGetParameters<T1, T2>(this Dictionary<T1, T2> dictionary) public static string ToGetParameters<T1, T2>(this Dictionary<T1, T2> dictionary)
{ {
return ((IReadOnlyDictionary<T1, T2>)dictionary).ToGetParameters(); return ((IReadOnlyDictionary<T1, T2>)dictionary).ToGetParameters();

View File

@ -3,7 +3,7 @@
using System; using System;
/// <summary> /// <summary>
/// Extension methods for <see cref="double"/>. /// Extension methods for <see cref="double" />.
/// </summary> /// </summary>
public static class DoubleExtensions public static class DoubleExtensions
{ {
@ -13,9 +13,11 @@
/// <param name="value">The value to clamp.</param> /// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum value.</param> /// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param> /// <param name="max">The maximum value.</param>
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it, /// <returns>
/// <paramref name="min"/> if <paramref name="value"/> is less than it, /// Returns <paramref name="max" /> if <paramref name="value" /> is greater than it,
/// or <paramref name="value"/> itself otherwise.</returns> /// <paramref name="min" /> if <paramref name="value" /> is less than it,
/// or <paramref name="value" /> itself otherwise.
/// </returns>
public static double Clamp(this double value, double min, double max) public static double Clamp(this double value, double min, double max)
{ {
return Math.Min(Math.Max(value, min), max); return Math.Min(Math.Max(value, min), max);
@ -25,39 +27,43 @@
/// Converts an angle from degrees to radians. /// Converts an angle from degrees to radians.
/// </summary> /// </summary>
/// <param name="angle">The angle in degrees.</param> /// <param name="angle">The angle in degrees.</param>
/// <returns>Returns <paramref name="angle"/> in radians.</returns> /// <returns>Returns <paramref name="angle" /> in radians.</returns>
public static double DegreesToRadians(this double angle) public static double DegreesToRadians(this double angle)
{ {
return Math.PI * angle / 180.0; return (Math.PI * angle) / 180.0;
} }
/// <summary> /// <summary>
/// Converts the <see cref="double"/> to a <see cref="byte"/>[]. /// Converts the <see cref="double" /> to a <see cref="byte" />[].
/// </summary> /// </summary>
/// <param name="number">The number to convert.</param> /// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="byte"/>[].</returns> /// <returns>Returns a <see cref="byte" />[].</returns>
public static byte[] GetBytes(this double number) public static byte[] GetBytes(this double number)
{ {
return BitConverter.GetBytes(number); return BitConverter.GetBytes(number);
} }
/// <summary> /// <summary>
/// Determines if the <see cref="double"/> is even. /// Determines if the <see cref="double" /> is even.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is even, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsEven(this double number) public static bool IsEven(this double number)
{ {
return Math.Abs(number % 2.0) < double.Epsilon; return Math.Abs(number % 2.0) < double.Epsilon;
} }
/// <summary> /// <summary>
/// Determines if the <see cref="double"/> is odd. /// Determines if the <see cref="double" /> is odd.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is odd, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsOdd(this double number) public static bool IsOdd(this double number)
{ {
return !number.IsEven(); return !number.IsEven();
@ -67,7 +73,7 @@
/// Converts an angle from radians to degrees. /// Converts an angle from radians to degrees.
/// </summary> /// </summary>
/// <param name="angle">The angle in radians.</param> /// <param name="angle">The angle in radians.</param>
/// <returns>Returns <paramref name="angle"/> in degrees.</returns> /// <returns>Returns <paramref name="angle" /> in degrees.</returns>
public static double RadiansToDegrees(this double angle) public static double RadiansToDegrees(this double angle)
{ {
return angle * (180.0 / Math.PI); return angle * (180.0 / Math.PI);
@ -79,7 +85,7 @@
/// <param name="v">The value to round.</param> /// <param name="v">The value to round.</param>
/// <param name="nearest">The nearest value.</param> /// <param name="nearest">The nearest value.</param>
/// <returns>Returns the rounded value.</returns> /// <returns>Returns the rounded value.</returns>
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; return Math.Round(v / nearest) * nearest;
} }

View File

@ -3,7 +3,7 @@
using System.Net; using System.Net;
/// <summary> /// <summary>
/// Extension methods for <see cref="EndPoint"/> and derived types. /// Extension methods for <see cref="EndPoint" /> and derived types.
/// </summary> /// </summary>
public static class EndPointExtensions public static class EndPointExtensions
{ {
@ -11,15 +11,17 @@
/// Gets the endpoint hostname. /// Gets the endpoint hostname.
/// </summary> /// </summary>
/// <param name="endPoint">The endpoint whose hostname to get.</param> /// <param name="endPoint">The endpoint whose hostname to get.</param>
/// <returns>Returns a <see cref="string"/> representing the hostname, which may be an IP or a DNS, or empty /// <returns>
/// string on failure.</returns> /// Returns a <see cref="string" /> representing the hostname, which may be an IP or a DNS, or empty
/// string on failure.
/// </returns>
public static string GetHost(this EndPoint endPoint) public static string GetHost(this EndPoint endPoint)
{ {
return endPoint switch return endPoint switch
{ {
IPEndPoint ip => ip.Address.ToString(), IPEndPoint ip => ip.Address.ToString(),
DnsEndPoint dns => dns.Host, DnsEndPoint dns => dns.Host,
_ => string.Empty, var _ => string.Empty,
}; };
} }
@ -27,14 +29,14 @@
/// Gets the endpoint port. /// Gets the endpoint port.
/// </summary> /// </summary>
/// <param name="endPoint">The endpoint whose port to get.</param> /// <param name="endPoint">The endpoint whose port to get.</param>
/// <returns>Returns an <see cref="int"/> representing the port, or 0 on failure.</returns> /// <returns>Returns an <see cref="int" /> representing the port, or 0 on failure.</returns>
public static int GetPort(this EndPoint endPoint) public static int GetPort(this EndPoint endPoint)
{ {
return endPoint switch return endPoint switch
{ {
IPEndPoint ip => ip.Port, IPEndPoint ip => ip.Port,
DnsEndPoint dns => dns.Port, DnsEndPoint dns => dns.Port,
_ => 0, var _ => 0,
}; };
} }
} }

View File

@ -4,21 +4,23 @@
using System.Linq; using System.Linq;
/// <summary> /// <summary>
/// Extension methods for <see cref="IEnumerable{T}"/>. /// Extension methods for <see cref="IEnumerable{T}" />.
/// </summary> /// </summary>
public static class EnumerableExtensions public static class EnumerableExtensions
{ {
/// <summary> /// <summary>
/// Splits <paramref name="value"/> into chunks of size <paramref name="chunkSize"/>. /// Splits <paramref name="value" /> into chunks of size <paramref name="chunkSize" />.
/// </summary> /// </summary>
/// <typeparam name="T">Any type.</typeparam> /// <typeparam name="T">Any type.</typeparam>
/// <param name="value">The collection to split.</param> /// <param name="value">The collection to split.</param>
/// <param name="chunkSize">The maximum length of the nested <see cref="byte"/> collection.</param> /// <param name="chunkSize">The maximum length of the nested <see cref="byte" /> collection.</param>
/// <returns>Returns an <see cref="IEnumerable{T}"/> of <see cref="IEnumerable{T}"/> of <see cref="byte"/> /// <returns>
/// values.</returns> /// Returns an <see cref="IEnumerable{T}" /> of <see cref="IEnumerable{T}" /> of <see cref="byte" />
/// values.
/// </returns>
public static IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> value, int chunkSize) public static IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> value, int chunkSize)
{ {
T[] enumerable = value.ToArray(); var enumerable = value.ToArray();
var count = enumerable.LongCount(); var count = enumerable.LongCount();
chunkSize = chunkSize.Clamp(1, enumerable.Length); chunkSize = chunkSize.Clamp(1, enumerable.Length);

View File

@ -3,7 +3,7 @@
using System; using System;
/// <summary> /// <summary>
/// Extension methods for <see cref="short"/>. /// Extension methods for <see cref="short" />.
/// </summary> /// </summary>
public static class Int16Extensions public static class Int16Extensions
{ {
@ -13,9 +13,11 @@
/// <param name="value">The value to clamp.</param> /// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum value.</param> /// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param> /// <param name="max">The maximum value.</param>
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it, /// <returns>
/// <paramref name="min"/> if <paramref name="value"/> is less than it, /// Returns <paramref name="max" /> if <paramref name="value" /> is greater than it,
/// or <paramref name="value"/> itself otherwise.</returns> /// <paramref name="min" /> if <paramref name="value" /> is less than it,
/// or <paramref name="value" /> itself otherwise.
/// </returns>
public static short Clamp(this short value, short min, short max) public static short Clamp(this short value, short min, short max)
{ {
return Math.Min(Math.Max(value, min), max); return Math.Min(Math.Max(value, min), max);
@ -27,9 +29,11 @@
/// <param name="value">The value to clamp.</param> /// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum value.</param> /// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param> /// <param name="max">The maximum value.</param>
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it, /// <returns>
/// <paramref name="min"/> if <paramref name="value"/> is less than it, /// Returns <paramref name="max" /> if <paramref name="value" /> is greater than it,
/// or <paramref name="value"/> itself otherwise.</returns> /// <paramref name="min" /> if <paramref name="value" /> is less than it,
/// or <paramref name="value" /> itself otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static ushort Clamp(this ushort value, ushort min, ushort max) public static ushort Clamp(this ushort value, ushort min, ushort max)
{ {
@ -37,23 +41,27 @@
} }
/// <summary> /// <summary>
/// Converts the <see cref="short"/> to a <see cref="DateTime"/> treating it as a Unix timestamp. /// Converts the <see cref="short" /> to a <see cref="DateTime" /> treating it as a Unix timestamp.
/// </summary> /// </summary>
/// <param name="timestamp">The timestamp.</param> /// <param name="timestamp">The timestamp.</param>
/// <param name="isMillis">Optional. Whether or not the input value should be treated as milliseconds. Defaults /// <param name="isMillis">
/// to <see langword="false"/>..</param> /// Optional. Whether or not the input value should be treated as milliseconds. Defaults
/// <returns>Returns a <see cref="DateTime"/> representing <paramref name="timestamp"/> seconds since the Unix /// to <see langword="false" />..
/// epoch.</returns> /// </param>
/// <returns>
/// Returns a <see cref="DateTime" /> representing <paramref name="timestamp" /> seconds since the Unix
/// epoch.
/// </returns>
public static DateTime FromUnixTimestamp(this short timestamp, bool isMillis = false) public static DateTime FromUnixTimestamp(this short timestamp, bool isMillis = false)
{ {
return ((long)timestamp).FromUnixTimestamp(isMillis); return ((long)timestamp).FromUnixTimestamp(isMillis);
} }
/// <summary> /// <summary>
/// Converts the <see cref="ushort"/> to a <see cref="byte"/>[]. /// Converts the <see cref="ushort" /> to a <see cref="byte" />[].
/// </summary> /// </summary>
/// <param name="number">The number to convert.</param> /// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="byte"/>[].</returns> /// <returns>Returns a <see cref="byte" />[].</returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static byte[] GetBytes(this ushort number) public static byte[] GetBytes(this ushort number)
{ {
@ -61,32 +69,36 @@
} }
/// <summary> /// <summary>
/// Converts the <see cref="short"/> to a <see cref="byte"/>[]. /// Converts the <see cref="short" /> to a <see cref="byte" />[].
/// </summary> /// </summary>
/// <param name="number">The number to convert.</param> /// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="byte"/>[].</returns> /// <returns>Returns a <see cref="byte" />[].</returns>
public static byte[] GetBytes(this short number) public static byte[] GetBytes(this short number)
{ {
return BitConverter.GetBytes(number); return BitConverter.GetBytes(number);
} }
/// <summary> /// <summary>
/// Determines if the <see cref="short"/> is even. /// Determines if the <see cref="short" /> is even.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is even, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsEven(this short number) public static bool IsEven(this short number)
{ {
return ((long)number).IsEven(); return ((long)number).IsEven();
} }
/// <summary> /// <summary>
/// Determines if the <see cref="ushort"/> is even. /// Determines if the <see cref="ushort" /> is even.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is even, <see langword="false" />
/// otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool IsEven(this ushort number) public static bool IsEven(this ushort number)
{ {
@ -94,22 +106,26 @@
} }
/// <summary> /// <summary>
/// Determines if the <see cref="short"/> is odd. /// Determines if the <see cref="short" /> is odd.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is odd, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsOdd(this short number) public static bool IsOdd(this short number)
{ {
return !number.IsEven(); return !number.IsEven();
} }
/// <summary> /// <summary>
/// Determines if the <see cref="ushort"/> is odd. /// Determines if the <see cref="ushort" /> is odd.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is odd, <see langword="false" />
/// otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool IsOdd(this ushort number) public static bool IsOdd(this ushort number)
{ {
@ -117,22 +133,26 @@
} }
/// <summary> /// <summary>
/// Determines if the <see cref="short"/> is a prime number. /// Determines if the <see cref="short" /> is a prime number.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is prime, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is prime, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsPrime(this short number) public static bool IsPrime(this short number)
{ {
return ((long)number).IsPrime(); return ((long)number).IsPrime();
} }
/// <summary> /// <summary>
/// Determines if the <see cref="short"/> is a prime number. /// Determines if the <see cref="short" /> is a prime number.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is prime, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is prime, <see langword="false" />
/// otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool IsPrime(this ushort number) public static bool IsPrime(this ushort number)
{ {
@ -143,8 +163,10 @@
/// Gets an boolean value that represents this integer. /// Gets an boolean value that represents this integer.
/// </summary> /// </summary>
/// <param name="value">The integer.</param> /// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0, /// <returns>
/// <see langword="true"/> otherwise.</returns> /// Returns <see langword="false" /> if <paramref name="value" /> is 0,
/// <see langword="true" /> otherwise.
/// </returns>
public static bool ToBoolean(this short value) public static bool ToBoolean(this short value)
{ {
return ((long)value).ToBoolean(); return ((long)value).ToBoolean();
@ -154,8 +176,10 @@
/// Gets an boolean value that represents this integer. /// Gets an boolean value that represents this integer.
/// </summary> /// </summary>
/// <param name="value">The integer.</param> /// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0, /// <returns>
/// <see langword="true"/> otherwise.</returns> /// Returns <see langword="false" /> if <paramref name="value" /> is 0,
/// <see langword="true" /> otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool ToBoolean(this ushort value) public static bool ToBoolean(this ushort value)
{ {

View File

@ -3,7 +3,7 @@
using System; using System;
/// <summary> /// <summary>
/// Extension methods for <see cref="int"/>. /// Extension methods for <see cref="int" />.
/// </summary> /// </summary>
public static class Int32Extensions public static class Int32Extensions
{ {
@ -13,9 +13,11 @@
/// <param name="value">The value to clamp.</param> /// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum value.</param> /// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param> /// <param name="max">The maximum value.</param>
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it, /// <returns>
/// <paramref name="min"/> if <paramref name="value"/> is less than it, /// Returns <paramref name="max" /> if <paramref name="value" /> is greater than it,
/// or <paramref name="value"/> itself otherwise.</returns> /// <paramref name="min" /> if <paramref name="value" /> is less than it,
/// or <paramref name="value" /> itself otherwise.
/// </returns>
public static int Clamp(this int value, int min, int max) public static int Clamp(this int value, int min, int max)
{ {
return Math.Min(Math.Max(value, min), max); return Math.Min(Math.Max(value, min), max);
@ -27,9 +29,11 @@
/// <param name="value">The value to clamp.</param> /// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum value.</param> /// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param> /// <param name="max">The maximum value.</param>
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it, /// <returns>
/// <paramref name="min"/> if <paramref name="value"/> is less than it, /// Returns <paramref name="max" /> if <paramref name="value" /> is greater than it,
/// or <paramref name="value"/> itself otherwise.</returns> /// <paramref name="min" /> if <paramref name="value" /> is less than it,
/// or <paramref name="value" /> itself otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static uint Clamp(this uint value, uint min, uint max) public static uint Clamp(this uint value, uint min, uint max)
{ {
@ -37,23 +41,27 @@
} }
/// <summary> /// <summary>
/// Converts the <see cref="int"/> to a <see cref="DateTime"/> treating it as a Unix timestamp. /// Converts the <see cref="int" /> to a <see cref="DateTime" /> treating it as a Unix timestamp.
/// </summary> /// </summary>
/// <param name="timestamp">The timestamp.</param> /// <param name="timestamp">The timestamp.</param>
/// <param name="isMillis">Optional. Whether or not the input value should be treated as milliseconds. Defaults /// <param name="isMillis">
/// to <see langword="false"/>..</param> /// Optional. Whether or not the input value should be treated as milliseconds. Defaults
/// <returns>Returns a <see cref="DateTime"/> representing <paramref name="timestamp"/> seconds since the Unix /// to <see langword="false" />..
/// epoch.</returns> /// </param>
/// <returns>
/// Returns a <see cref="DateTime" /> representing <paramref name="timestamp" /> seconds since the Unix
/// epoch.
/// </returns>
public static DateTime FromUnixTimestamp(this int timestamp, bool isMillis = false) public static DateTime FromUnixTimestamp(this int timestamp, bool isMillis = false)
{ {
return ((long)timestamp).FromUnixTimestamp(isMillis); return ((long)timestamp).FromUnixTimestamp(isMillis);
} }
/// <summary> /// <summary>
/// Converts the <see cref="uint"/> to a <see cref="byte"/>[]. /// Converts the <see cref="uint" /> to a <see cref="byte" />[].
/// </summary> /// </summary>
/// <param name="number">The number to convert.</param> /// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="byte"/>[].</returns> /// <returns>Returns a <see cref="byte" />[].</returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static byte[] GetBytes(this uint number) public static byte[] GetBytes(this uint number)
{ {
@ -61,32 +69,36 @@
} }
/// <summary> /// <summary>
/// Converts the <see cref="int"/> to a <see cref="byte"/>[]. /// Converts the <see cref="int" /> to a <see cref="byte" />[].
/// </summary> /// </summary>
/// <param name="number">The number to convert.</param> /// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="byte"/>[].</returns> /// <returns>Returns a <see cref="byte" />[].</returns>
public static byte[] GetBytes(this int number) public static byte[] GetBytes(this int number)
{ {
return BitConverter.GetBytes(number); return BitConverter.GetBytes(number);
} }
/// <summary> /// <summary>
/// Determines if the <see cref="int"/> is even. /// Determines if the <see cref="int" /> is even.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is even, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsEven(this int number) public static bool IsEven(this int number)
{ {
return ((long)number).IsEven(); return ((long)number).IsEven();
} }
/// <summary> /// <summary>
/// Determines if the <see cref="uint"/> is even. /// Determines if the <see cref="uint" /> is even.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is even, <see langword="false" />
/// otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool IsEven(this uint number) public static bool IsEven(this uint number)
{ {
@ -94,22 +106,26 @@
} }
/// <summary> /// <summary>
/// Determines if the <see cref="int"/> is odd. /// Determines if the <see cref="int" /> is odd.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is odd, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsOdd(this int number) public static bool IsOdd(this int number)
{ {
return !number.IsEven(); return !number.IsEven();
} }
/// <summary> /// <summary>
/// Determines if the <see cref="uint"/> is odd. /// Determines if the <see cref="uint" /> is odd.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is odd, <see langword="false" />
/// otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool IsOdd(this uint number) public static bool IsOdd(this uint number)
{ {
@ -117,11 +133,13 @@
} }
/// <summary> /// <summary>
/// Determines if the <see cref="int"/> is a prime number. /// Determines if the <see cref="int" /> is a prime number.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is prime, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is prime, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsPrime(this int number) public static bool IsPrime(this int number)
{ {
return ((long)number).IsPrime(); return ((long)number).IsPrime();
@ -131,8 +149,10 @@
/// Gets an boolean value that represents this integer. /// Gets an boolean value that represents this integer.
/// </summary> /// </summary>
/// <param name="value">The integer.</param> /// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0, /// <returns>
/// <see langword="true"/> otherwise.</returns> /// Returns <see langword="false" /> if <paramref name="value" /> is 0,
/// <see langword="true" /> otherwise.
/// </returns>
public static bool ToBoolean(this int value) public static bool ToBoolean(this int value)
{ {
return ((long)value).ToBoolean(); return ((long)value).ToBoolean();
@ -142,8 +162,10 @@
/// Gets an boolean value that represents this integer. /// Gets an boolean value that represents this integer.
/// </summary> /// </summary>
/// <param name="value">The integer.</param> /// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0, /// <returns>
/// <see langword="true"/> otherwise.</returns> /// Returns <see langword="false" /> if <paramref name="value" /> is 0,
/// <see langword="true" /> otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool ToBoolean(this uint value) public static bool ToBoolean(this uint value)
{ {

View File

@ -3,7 +3,7 @@
using System; using System;
/// <summary> /// <summary>
/// Extension methods for <see cref="long"/>. /// Extension methods for <see cref="long" />.
/// </summary> /// </summary>
public static class Int64Extensions public static class Int64Extensions
{ {
@ -13,9 +13,11 @@
/// <param name="value">The value to clamp.</param> /// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum value.</param> /// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param> /// <param name="max">The maximum value.</param>
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it, /// <returns>
/// <paramref name="min"/> if <paramref name="value"/> is less than it, /// Returns <paramref name="max" /> if <paramref name="value" /> is greater than it,
/// or <paramref name="value"/> itself otherwise.</returns> /// <paramref name="min" /> if <paramref name="value" /> is less than it,
/// or <paramref name="value" /> itself otherwise.
/// </returns>
public static long Clamp(this long value, long min, long max) public static long Clamp(this long value, long min, long max)
{ {
return Math.Min(Math.Max(value, min), max); return Math.Min(Math.Max(value, min), max);
@ -27,9 +29,11 @@
/// <param name="value">The value to clamp.</param> /// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum value.</param> /// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param> /// <param name="max">The maximum value.</param>
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it, /// <returns>
/// <paramref name="min"/> if <paramref name="value"/> is less than it, /// Returns <paramref name="max" /> if <paramref name="value" /> is greater than it,
/// or <paramref name="value"/> itself otherwise.</returns> /// <paramref name="min" /> if <paramref name="value" /> is less than it,
/// or <paramref name="value" /> itself otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static ulong Clamp(this ulong value, ulong min, ulong max) public static ulong Clamp(this ulong value, ulong min, ulong max)
{ {
@ -37,16 +41,20 @@
} }
/// <summary> /// <summary>
/// Converts the <see cref="long"/> to a <see cref="DateTime"/> treating it as a Unix timestamp. /// Converts the <see cref="long" /> to a <see cref="DateTime" /> treating it as a Unix timestamp.
/// </summary> /// </summary>
/// <param name="timestamp">The timestamp.</param> /// <param name="timestamp">The timestamp.</param>
/// <param name="isMillis">Optional. Whether or not the input value should be treated as milliseconds. Defaults /// <param name="isMillis">
/// to <see langword="false"/>.</param> /// Optional. Whether or not the input value should be treated as milliseconds. Defaults
/// <returns>Returns a <see cref="DateTime"/> representing <paramref name="timestamp"/> seconds since the Unix /// to <see langword="false" />.
/// epoch.</returns> /// </param>
/// <returns>
/// Returns a <see cref="DateTime" /> representing <paramref name="timestamp" /> seconds since the Unix
/// epoch.
/// </returns>
public static DateTime FromUnixTimestamp(this long timestamp, bool isMillis = false) public static DateTime FromUnixTimestamp(this long timestamp, bool isMillis = false)
{ {
DateTimeOffset offset = isMillis var offset = isMillis
? DateTimeOffset.FromUnixTimeMilliseconds(timestamp) ? DateTimeOffset.FromUnixTimeMilliseconds(timestamp)
: DateTimeOffset.FromUnixTimeSeconds(timestamp); : DateTimeOffset.FromUnixTimeSeconds(timestamp);
@ -54,10 +62,10 @@
} }
/// <summary> /// <summary>
/// Converts the <see cref="ulong"/> to a <see cref="byte"/>[]. /// Converts the <see cref="ulong" /> to a <see cref="byte" />[].
/// </summary> /// </summary>
/// <param name="number">The number to convert.</param> /// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="byte"/>[].</returns> /// <returns>Returns a <see cref="byte" />[].</returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static byte[] GetBytes(this ulong number) public static byte[] GetBytes(this ulong number)
{ {
@ -65,32 +73,36 @@
} }
/// <summary> /// <summary>
/// Converts the <see cref="long"/> to a <see cref="byte"/>[]. /// Converts the <see cref="long" /> to a <see cref="byte" />[].
/// </summary> /// </summary>
/// <param name="number">The number to convert.</param> /// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="byte"/>[].</returns> /// <returns>Returns a <see cref="byte" />[].</returns>
public static byte[] GetBytes(this long number) public static byte[] GetBytes(this long number)
{ {
return BitConverter.GetBytes(number); return BitConverter.GetBytes(number);
} }
/// <summary> /// <summary>
/// Determines if the <see cref="long"/> is even. /// Determines if the <see cref="long" /> is even.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is even, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsEven(this long number) public static bool IsEven(this long number)
{ {
return Math.Abs(number % 2.0) < double.Epsilon; return Math.Abs(number % 2.0) < double.Epsilon;
} }
/// <summary> /// <summary>
/// Determines if the <see cref="ulong"/> is even. /// Determines if the <see cref="ulong" /> is even.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is even, <see langword="false" />
/// otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool IsEven(this ulong number) public static bool IsEven(this ulong number)
{ {
@ -98,22 +110,26 @@
} }
/// <summary> /// <summary>
/// Determines if the <see cref="long"/> is odd. /// Determines if the <see cref="long" /> is odd.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is odd, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsOdd(this long number) public static bool IsOdd(this long number)
{ {
return !IsEven(number); return !IsEven(number);
} }
/// <summary> /// <summary>
/// Determines if the <see cref="ulong"/> is odd. /// Determines if the <see cref="ulong" /> is odd.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is odd, <see langword="false" />
/// otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool IsOdd(this ulong number) public static bool IsOdd(this ulong number)
{ {
@ -121,11 +137,13 @@
} }
/// <summary> /// <summary>
/// Determines if the <see cref="long"/> is a prime number. /// Determines if the <see cref="long" /> is a prime number.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is prime, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is prime, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsPrime(this long number) public static bool IsPrime(this long number)
{ {
if (number <= 1) if (number <= 1)
@ -156,11 +174,13 @@
} }
/// <summary> /// <summary>
/// Determines if the <see cref="ulong"/> is a prime number. /// Determines if the <see cref="ulong" /> is a prime number.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is prime, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is prime, <see langword="false" />
/// otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool IsPrime(this ulong number) public static bool IsPrime(this ulong number)
{ {
@ -195,8 +215,10 @@
/// Gets an boolean value that represents this integer. /// Gets an boolean value that represents this integer.
/// </summary> /// </summary>
/// <param name="value">The integer.</param> /// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0, /// <returns>
/// <see langword="true"/> otherwise.</returns> /// Returns <see langword="false" /> if <paramref name="value" /> is 0,
/// <see langword="true" /> otherwise.
/// </returns>
public static bool ToBoolean(this long value) public static bool ToBoolean(this long value)
{ {
return value != 0; return value != 0;
@ -206,8 +228,10 @@
/// Gets an boolean value that represents this integer. /// Gets an boolean value that represents this integer.
/// </summary> /// </summary>
/// <param name="value">The integer.</param> /// <param name="value">The integer.</param>
/// <returns>Returns <see langword="false"/> if <paramref name="value"/> is 0, /// <returns>
/// <see langword="true"/> otherwise.</returns> /// Returns <see langword="false" /> if <paramref name="value" /> is 0,
/// <see langword="true" /> otherwise.
/// </returns>
[CLSCompliant(false)] [CLSCompliant(false)]
public static bool ToBoolean(this ulong value) public static bool ToBoolean(this ulong value)
{ {

View File

@ -5,51 +5,51 @@
using System.Linq; using System.Linq;
/// <summary> /// <summary>
/// Extension methods for <see cref="IList{T}"/>. /// Extension methods for <see cref="IList{T}" />.
/// </summary> /// </summary>
public static class ListExtensions public static class ListExtensions
{ {
/// <summary> /// <summary>
/// Returns a random element from <paramref name="source"/> using a new <see cref="Random"/> instance. /// Returns a random element from <paramref name="source" /> using a new <see cref="Random" /> instance.
/// </summary> /// </summary>
/// <typeparam name="T">The collection type.</typeparam> /// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to draw from.</param> /// <param name="source">The collection to draw from.</param>
/// <returns>Returns a random element of type <see cref="T"/> from <paramref name="source"/>.</returns> /// <returns>Returns a random element of type <see cref="T" /> from <paramref name="source" />.</returns>
public static T OneOf<T>(this IEnumerable<T> source) public static T OneOf<T>(this IEnumerable<T> source)
{ {
return source.OneOf(new Random()); return source.OneOf(new Random());
} }
/// <summary> /// <summary>
/// Returns a random element from <paramref name="source"/> using the <see cref="Random"/> instance. /// Returns a random element from <paramref name="source" /> using the <see cref="Random" /> instance.
/// </summary> /// </summary>
/// <typeparam name="T">The collection type.</typeparam> /// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to draw from.</param> /// <param name="source">The collection to draw from.</param>
/// <param name="random">The <see cref="Random"/> instance.</param> /// <param name="random">The <see cref="Random" /> instance.</param>
/// <returns>Returns a random element of type <see cref="T"/> from <paramref name="source"/>.</returns> /// <returns>Returns a random element of type <see cref="T" /> from <paramref name="source" />.</returns>
public static T OneOf<T>(this IEnumerable<T> source, Random random) public static T OneOf<T>(this IEnumerable<T> source, Random random)
{ {
return source.ToList().OneOf(random); return source.ToList().OneOf(random);
} }
/// <summary> /// <summary>
/// Returns a random element from <paramref name="source"/> using a new <see cref="Random"/> instance. /// Returns a random element from <paramref name="source" /> using a new <see cref="Random" /> instance.
/// </summary> /// </summary>
/// <typeparam name="T">The collection type.</typeparam> /// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to draw from.</param> /// <param name="source">The collection to draw from.</param>
/// <returns>Returns a random element of type <see cref="T"/> from <paramref name="source"/>.</returns> /// <returns>Returns a random element of type <see cref="T" /> from <paramref name="source" />.</returns>
public static T OneOf<T>(this IList<T> source) public static T OneOf<T>(this IList<T> source)
{ {
return source.OneOf(new Random()); return source.OneOf(new Random());
} }
/// <summary> /// <summary>
/// Returns a random element from <paramref name="source"/> using the <see cref="Random"/> instance. /// Returns a random element from <paramref name="source" /> using the <see cref="Random" /> instance.
/// </summary> /// </summary>
/// <typeparam name="T">The collection type.</typeparam> /// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to draw from.</param> /// <param name="source">The collection to draw from.</param>
/// <param name="random">The <see cref="Random"/> instance.</param> /// <param name="random">The <see cref="Random" /> instance.</param>
/// <returns>Returns a random element of type <see cref="T"/> from <paramref name="source"/>.</returns> /// <returns>Returns a random element of type <see cref="T" /> from <paramref name="source" />.</returns>
public static T OneOf<T>(this IList<T> source, Random random) public static T OneOf<T>(this IList<T> source, Random random)
{ {
return random.OneOf(source); return random.OneOf(source);
@ -60,7 +60,7 @@
/// </summary> /// </summary>
/// <typeparam name="T">The collection type.</typeparam> /// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to shuffle.</param> /// <param name="source">The collection to shuffle.</param>
/// <returns>Returns <paramref name="source"/> shuffled.</returns> /// <returns>Returns <paramref name="source" /> shuffled.</returns>
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source) public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
{ {
return source.Shuffle(new Random()); return source.Shuffle(new Random());
@ -71,8 +71,8 @@
/// </summary> /// </summary>
/// <typeparam name="T">The collection type.</typeparam> /// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to shuffle.</param> /// <param name="source">The collection to shuffle.</param>
/// <param name="random">The <see cref="Random"/> instance.</param> /// <param name="random">The <see cref="Random" /> instance.</param>
/// <returns>Returns <paramref name="source"/> shuffled.</returns> /// <returns>Returns <paramref name="source" /> shuffled.</returns>
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source, Random random) public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source, Random random)
{ {
return source.OrderBy(_ => random.Next()); return source.OrderBy(_ => random.Next());
@ -83,7 +83,7 @@
/// </summary> /// </summary>
/// <typeparam name="T">The collection type.</typeparam> /// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to shuffle.</param> /// <param name="source">The collection to shuffle.</param>
/// <returns>Returns <paramref name="source"/> shuffled.</returns> /// <returns>Returns <paramref name="source" /> shuffled.</returns>
public static IEnumerable<T> Shuffle<T>(this IList<T> source) public static IEnumerable<T> Shuffle<T>(this IList<T> source)
{ {
return source.Shuffle(new Random()); return source.Shuffle(new Random());
@ -94,8 +94,8 @@
/// </summary> /// </summary>
/// <typeparam name="T">The collection type.</typeparam> /// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to shuffle.</param> /// <param name="source">The collection to shuffle.</param>
/// <param name="random">The <see cref="Random"/> instance.</param> /// <param name="random">The <see cref="Random" /> instance.</param>
/// <returns>Returns <paramref name="source"/> shuffled.</returns> /// <returns>Returns <paramref name="source" /> shuffled.</returns>
public static IEnumerable<T> Shuffle<T>(this IList<T> source, Random random) public static IEnumerable<T> Shuffle<T>(this IList<T> source, Random random)
{ {
return source.OrderBy(_ => random.Next()); return source.OrderBy(_ => random.Next());

View File

@ -5,24 +5,26 @@
using System.Linq; using System.Linq;
/// <summary> /// <summary>
/// Extension methods for <see cref="Random"/>. /// Extension methods for <see cref="Random" />.
/// </summary> /// </summary>
public static class RandomExtensions public static class RandomExtensions
{ {
/// <summary> /// <summary>
/// Gets the <see cref="System.Random"/> instance to which other extension methods may refer, when one is /// Gets the <see cref="System.Random" /> instance to which other extension methods may refer, when one is
/// needed but not provided. /// needed but not provided.
/// </summary> /// </summary>
internal static Random Random { get; } = new Random(); internal static Random Random { get; } = new Random();
/// <summary> /// <summary>
/// Returns either <see langword="true"/> or <see langword="false"/> based on <paramref name="random"/>'s next /// Returns either <see langword="true" /> or <see langword="false" /> based on <paramref name="random" />'s next
/// generation. /// generation.
/// </summary> /// </summary>
/// <param name="random">The <see cref="System.Random"/> instance.</param> /// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <returns>Returns <see langword="true"/> or <see langword="false"/> depending on the return value /// <returns>
/// from <see cref="System.Random.Next(int)"/>.</returns> /// Returns <see langword="true" /> or <see langword="false" /> depending on the return value
/// <exception cref="ArgumentNullException"><paramref name="random"/> is <see langword="null"/>.</exception> /// from <see cref="System.Random.Next(int)" />.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
public static bool CoinToss(this Random random) public static bool CoinToss(this Random random)
{ {
if (random is null) if (random is null)
@ -34,26 +36,28 @@
} }
/// <summary> /// <summary>
/// Returns a random element from <paramref name="source"/> using the <see cref="System.Random"/> instance. /// Returns a random element from <paramref name="source" /> using the <see cref="System.Random" /> instance.
/// </summary> /// </summary>
/// <typeparam name="T">The collection type.</typeparam> /// <typeparam name="T">The collection type.</typeparam>
/// <param name="random">The <see cref="System.Random"/> instance.</param> /// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <param name="source">The collection from which to draw.</param> /// <param name="source">The collection from which to draw.</param>
/// <returns>Returns a random element of type <see cref="T"/> from <paramref name="source"/>.</returns> /// <returns>Returns a random element of type <see cref="T" /> from <paramref name="source" />.</returns>
public static T OneOf<T>(this Random random, params T[] source) public static T OneOf<T>(this Random random, params T[] source)
{ {
return source.ToList().OneOf(random); return source.ToList().OneOf(random);
} }
/// <summary> /// <summary>
/// Returns a random element from <paramref name="source"/> using the <see cref="System.Random"/> instance. /// Returns a random element from <paramref name="source" /> using the <see cref="System.Random" /> instance.
/// </summary> /// </summary>
/// <typeparam name="T">The collection type.</typeparam> /// <typeparam name="T">The collection type.</typeparam>
/// <param name="random">The <see cref="System.Random"/> instance.</param> /// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <param name="source">The collection from which to draw.</param> /// <param name="source">The collection from which to draw.</param>
/// <returns>Returns a random element of type <see cref="T"/> from <paramref name="source"/>.</returns> /// <returns>Returns a random element of type <see cref="T" /> from <paramref name="source" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="random"/> or <paramref name="source"/> is /// <exception cref="ArgumentNullException">
/// <see langword="null"/>.</exception> /// <paramref name="random" /> or <paramref name="source" /> is
/// <see langword="null" />.
/// </exception>
public static T OneOf<T>(this Random random, IList<T> source) public static T OneOf<T>(this Random random, IList<T> source)
{ {
if (random is null) if (random is null)

View File

@ -10,13 +10,15 @@
public static class ReflectionExtensions public static class ReflectionExtensions
{ {
/// <summary> /// <summary>
/// Gets the value set in this member's annotated <see cref="DefaultValueAttribute"/>, or /// Gets the value set in this member's annotated <see cref="DefaultValueAttribute" />, or
/// <see langword="default"/> if none exists. /// <see langword="default" /> if none exists.
/// </summary> /// </summary>
/// <param name="member">The member.</param> /// <param name="member">The member.</param>
/// <returns>Returns an <see cref="object"/> representing the value stored in this member's /// <returns>
/// <see cref="DefaultValueAttribute"/>.</returns> /// Returns an <see cref="object" /> representing the value stored in this member's
/// <exception cref="ArgumentNullException"><paramref name="member"/> is <see langword="null"/>.</exception> /// <see cref="DefaultValueAttribute" />.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="member" /> is <see langword="null" />.</exception>
public static object GetDefaultValue(this MemberInfo member) public static object GetDefaultValue(this MemberInfo member)
{ {
if (member is null) if (member is null)
@ -33,14 +35,16 @@
} }
/// <summary> /// <summary>
/// Gets the value set in this member's annotated <see cref="DefaultValueAttribute"/>, or /// Gets the value set in this member's annotated <see cref="DefaultValueAttribute" />, or
/// <see langword="default"/> if none exists. /// <see langword="default" /> if none exists.
/// </summary> /// </summary>
/// <typeparam name="T">The type to which the value should cast.</typeparam> /// <typeparam name="T">The type to which the value should cast.</typeparam>
/// <param name="member">The member.</param> /// <param name="member">The member.</param>
/// <returns>Returns an instance of <typeparamref name="T"/> representing the value stored in this member's /// <returns>
/// <see cref="DefaultValueAttribute"/>.</returns> /// Returns an instance of <typeparamref name="T" /> representing the value stored in this member's
/// <exception cref="ArgumentNullException"><paramref name="member"/> is <see langword="null"/>.</exception> /// <see cref="DefaultValueAttribute" />.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="member" /> is <see langword="null" />.</exception>
public static T GetDefaultValue<T>(this MemberInfo member) public static T GetDefaultValue<T>(this MemberInfo member)
{ {
if (member is null) if (member is null)
@ -52,13 +56,15 @@
} }
/// <summary> /// <summary>
/// Gets the value set in this member's annotated <see cref="DescriptionAttribute"/>, or /// Gets the value set in this member's annotated <see cref="DescriptionAttribute" />, or
/// <see langword="null"/> if none exists. /// <see langword="null" /> if none exists.
/// </summary> /// </summary>
/// <param name="member">The member.</param> /// <param name="member">The member.</param>
/// <returns>Returns an instance of <typeparamref name="T"/> representing the value stored in this member's /// <returns>
/// <see cref="DescriptionAttribute"/>.</returns> /// Returns a string representing the value stored in this member's
/// <exception cref="ArgumentNullException"><paramref name="member"/> is <see langword="null"/>.</exception> /// <see cref="DescriptionAttribute" />.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="member" /> is <see langword="null" />.</exception>
public static string GetDescription(this MemberInfo member) public static string GetDescription(this MemberInfo member)
{ {
if (member is null) if (member is null)
@ -79,14 +85,18 @@
/// to a selector delegate in order to select one or more the members in the attribute. /// to a selector delegate in order to select one or more the members in the attribute.
/// </summary> /// </summary>
/// <typeparam name="TAttribute">The attribute type.</typeparam> /// <typeparam name="TAttribute">The attribute type.</typeparam>
/// <typeparam name="TReturn">The return type of the <paramref name="selector"/> delegate.</typeparam> /// <typeparam name="TReturn">The return type of the <paramref name="selector" /> delegate.</typeparam>
/// <param name="member">The member.</param> /// <param name="member">The member.</param>
/// <param name="selector">The selector delegate.</param> /// <param name="selector">The selector delegate.</param>
/// <returns>Returns an instance of <typeparamref name="TReturn"/> as provided from /// <returns>
/// <paramref name="selector"/>.</returns> /// Returns an instance of <typeparamref name="TReturn" /> as provided from
/// <exception cref="ArgumentNullException"><paramref name="member"/> is <see langword="null"/> /// <paramref name="selector" />.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="member" /> is <see langword="null" />
/// -or- /// -or-
/// <paramref name="selector"/> is <see langword="null"/>.</exception> /// <paramref name="selector" /> is <see langword="null" />.
/// </exception>
public static TReturn SelectFromCustomAttribute<TAttribute, TReturn>( public static TReturn SelectFromCustomAttribute<TAttribute, TReturn>(
this MemberInfo member, this MemberInfo member,
Func<TAttribute, TReturn> selector) Func<TAttribute, TReturn> selector)

View File

@ -3,7 +3,7 @@
using System; using System;
/// <summary> /// <summary>
/// Extension methods for <see cref="float"/>. /// Extension methods for <see cref="float" />.
/// </summary> /// </summary>
public static class SingleExtensions public static class SingleExtensions
{ {
@ -13,9 +13,11 @@
/// <param name="value">The value to clamp.</param> /// <param name="value">The value to clamp.</param>
/// <param name="min">The minimum value.</param> /// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param> /// <param name="max">The maximum value.</param>
/// <returns>Returns <paramref name="max"/> if <paramref name="value"/> is greater than it, /// <returns>
/// <paramref name="min"/> if <paramref name="value"/> is less than it, /// Returns <paramref name="max" /> if <paramref name="value" /> is greater than it,
/// or <paramref name="value"/> itself otherwise.</returns> /// <paramref name="min" /> if <paramref name="value" /> is less than it,
/// or <paramref name="value" /> itself otherwise.
/// </returns>
public static float Clamp(this float value, float min, float max) public static float Clamp(this float value, float min, float max)
{ {
return Math.Min(Math.Max(value, min), max); return Math.Min(Math.Max(value, min), max);
@ -25,39 +27,43 @@
/// Converts an angle from degrees to radians. /// Converts an angle from degrees to radians.
/// </summary> /// </summary>
/// <param name="angle">The angle in degrees.</param> /// <param name="angle">The angle in degrees.</param>
/// <returns>Returns <paramref name="angle"/> in radians.</returns> /// <returns>Returns <paramref name="angle" /> in radians.</returns>
public static float DegreesToRadians(this float angle) public static float DegreesToRadians(this float angle)
{ {
return (float)((double)angle).DegreesToRadians(); return (float)((double)angle).DegreesToRadians();
} }
/// <summary> /// <summary>
/// Converts the <see cref="float"/> to a <see cref="byte"/>[]. /// Converts the <see cref="float" /> to a <see cref="byte" />[].
/// </summary> /// </summary>
/// <param name="number">The number to convert.</param> /// <param name="number">The number to convert.</param>
/// <returns>Returns a <see cref="byte"/>[].</returns> /// <returns>Returns a <see cref="byte" />[].</returns>
public static byte[] GetBytes(this float number) public static byte[] GetBytes(this float number)
{ {
return BitConverter.GetBytes(number); return BitConverter.GetBytes(number);
} }
/// <summary> /// <summary>
/// Determines if the <see cref="float"/> is even. /// Determines if the <see cref="float" /> is even.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is even, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsEven(this float number) public static bool IsEven(this float number)
{ {
return ((double)number).IsEven(); return ((double)number).IsEven();
} }
/// <summary> /// <summary>
/// Determines if the <see cref="float"/> is odd. /// Determines if the <see cref="float" /> is odd.
/// </summary> /// </summary>
/// <param name="number">The number.</param> /// <param name="number">The number.</param>
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if <paramref name="number" /> is odd, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsOdd(this float number) public static bool IsOdd(this float number)
{ {
return !number.IsEven(); return !number.IsEven();
@ -67,7 +73,7 @@
/// Converts an angle from radians to degrees. /// Converts an angle from radians to degrees.
/// </summary> /// </summary>
/// <param name="angle">The angle in radians.</param> /// <param name="angle">The angle in radians.</param>
/// <returns>Returns <paramref name="angle"/> in degrees.</returns> /// <returns>Returns <paramref name="angle" /> in degrees.</returns>
public static float RadiansToDegrees(this float angle) public static float RadiansToDegrees(this float angle)
{ {
return (float)((double)angle).RadiansToDegrees(); return (float)((double)angle).RadiansToDegrees();
@ -79,7 +85,7 @@
/// <param name="v">The value to round.</param> /// <param name="v">The value to round.</param>
/// <param name="nearest">The nearest value.</param> /// <param name="nearest">The nearest value.</param>
/// <returns>Returns the rounded value.</returns> /// <returns>Returns the rounded value.</returns>
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); return (float)((double)v).Round(nearest);
} }

View File

@ -2,21 +2,20 @@
{ {
using System; using System;
using System.IO; using System.IO;
using System.Reflection;
using System.Security.Cryptography; using System.Security.Cryptography;
/// <summary> /// <summary>
/// Extension methods for <see cref="Stream"/>. /// Extension methods for <see cref="Stream" />.
/// </summary> /// </summary>
public static class StreamExtensions public static class StreamExtensions
{ {
/// <summary> /// <summary>
/// Returns the hash of a stream using the specified hashing algorithm. /// Returns the hash of a stream using the specified hashing algorithm.
/// </summary> /// </summary>
/// <typeparam name="T">A <see cref="HashAlgorithm"/> derived type.</typeparam> /// <typeparam name="T">A <see cref="HashAlgorithm" /> derived type.</typeparam>
/// <param name="stream">The stream whose hash is to be computed.</param> /// <param name="stream">The stream whose hash is to be computed.</param>
/// <returns>Returns a <see cref="byte"/> array representing the hash of the stream.</returns> /// <returns>Returns a <see cref="byte" /> array representing the hash of the stream.</returns>
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="stream" /> is <see langword="null" />.</exception>
public static byte[] GetHash<T>(this Stream stream) public static byte[] GetHash<T>(this Stream stream)
where T : HashAlgorithm where T : HashAlgorithm
{ {
@ -25,7 +24,7 @@
throw new ArgumentNullException(nameof(stream)); throw new ArgumentNullException(nameof(stream));
} }
MethodInfo create = typeof(T).GetMethod("Create", Array.Empty<Type>()); var create = typeof(T).GetMethod("Create", Array.Empty<Type>());
using var crypt = (T)create?.Invoke(null, null); using var crypt = (T)create?.Invoke(null, null);
return crypt?.ComputeHash(stream); return crypt?.ComputeHash(stream);
} }

View File

@ -8,7 +8,7 @@
using System.Text; using System.Text;
/// <summary> /// <summary>
/// Extension methods for <see cref="string"/>. /// Extension methods for <see cref="string" />.
/// </summary> /// </summary>
public static class StringExtensions public static class StringExtensions
{ {
@ -38,13 +38,17 @@
/// <param name="str">The input string.</param> /// <param name="str">The input string.</param>
/// <param name="from">The input encoding.</param> /// <param name="from">The input encoding.</param>
/// <param name="to">The output encoding.</param> /// <param name="to">The output encoding.</param>
/// <returns>Returns a new <see cref="string"/> with its data converted to /// <returns>
/// <paramref name="to"/>.</returns> /// Returns a new <see cref="string" /> with its data converted to
/// <exception cref="ArgumentNullException"><paramref name="str"/> is <see langword="null"/> /// <paramref name="to" />.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="str" /> is <see langword="null" />
/// - or - /// - or -
/// <paramref name="from"/> is <see langword="null"/> /// <paramref name="from" /> is <see langword="null" />
/// -or /// -or
/// <paramref name="to"/> is <see langword="null"/>.</exception> /// <paramref name="to" /> is <see langword="null" />.
/// </exception>
public static string ChangeEncoding(this string str, Encoding from, Encoding to) public static string ChangeEncoding(this string str, Encoding from, Encoding to)
{ {
if (str is null) if (str is null)
@ -66,27 +70,31 @@
} }
/// <summary> /// <summary>
/// Parses a <see cref="string"/> into an <see cref="Enum"/>. /// Parses a <see cref="string" /> into an <see cref="Enum" />.
/// </summary> /// </summary>
/// <typeparam name="T">The type of the <see cref="Enum"/>.</typeparam> /// <typeparam name="T">The type of the <see cref="Enum" />.</typeparam>
/// <param name="value">The <see cref="string"/> value to parse.</param> /// <param name="value">The <see cref="string" /> value to parse.</param>
/// <returns>The <see cref="Enum"/> value corresponding to the <see cref="string"/>.</returns> /// <returns>The <see cref="Enum" /> value corresponding to the <see cref="string" />.</returns>
/// <remarks>Credit for this method goes to Scott Dorman: /// <remarks>
/// (http://geekswithblogs.net/sdorman/Default.aspx)</remarks> /// Credit for this method goes to Scott Dorman:
/// (http://geekswithblogs.net/sdorman/Default.aspx).
/// </remarks>
public static T EnumParse<T>(this string value) public static T EnumParse<T>(this string value)
{ {
return value.EnumParse<T>(false); return value.EnumParse<T>(false);
} }
/// <summary> /// <summary>
/// Parses a <see cref="string"/> into an <see cref="Enum"/>. /// Parses a <see cref="string" /> into an <see cref="Enum" />.
/// </summary> /// </summary>
/// <typeparam name="T">The type of the <see cref="Enum"/>.</typeparam> /// <typeparam name="T">The type of the <see cref="Enum" />.</typeparam>
/// <param name="value">The <see cref="string"/> value to parse.</param> /// <param name="value">The <see cref="string" /> value to parse.</param>
/// <param name="ignoreCase">Whether or not to ignore casing.</param> /// <param name="ignoreCase">Whether or not to ignore casing.</param>
/// <returns>The <see cref="Enum"/> value corresponding to the <see cref="string"/>.</returns> /// <returns>The <see cref="Enum" /> value corresponding to the <see cref="string" />.</returns>
/// <remarks>Credit for this method goes to Scott Dorman: /// <remarks>
/// (http://geekswithblogs.net/sdorman/Default.aspx)</remarks> /// Credit for this method goes to Scott Dorman:
/// (http://geekswithblogs.net/sdorman/Default.aspx).
/// </remarks>
public static T EnumParse<T>(this string value, bool ignoreCase) public static T EnumParse<T>(this string value, bool ignoreCase)
{ {
if (value is null) if (value is null)
@ -101,7 +109,7 @@
throw new ArgumentException(Resource.EnumParseEmptyStringException, nameof(value)); throw new ArgumentException(Resource.EnumParseEmptyStringException, nameof(value));
} }
Type t = typeof(T); var t = typeof(T);
if (!t.IsEnum) if (!t.IsEnum)
{ {
@ -112,24 +120,26 @@
} }
/// <summary> /// <summary>
/// Gets a <see cref="byte"/>[] representing the value the <see cref="string"/> with /// Gets a <see cref="byte" />[] representing the value the <see cref="string" /> with
/// <see cref="Encoding.UTF8"/> encoding. /// <see cref="Encoding.UTF8" /> encoding.
/// </summary> /// </summary>
/// <param name="str">The string to convert.</param> /// <param name="str">The string to convert.</param>
/// <returns>Returns a <see cref="byte"/>[].</returns> /// <returns>Returns a <see cref="byte" />[].</returns>
public static byte[] GetBytes(this string str) public static byte[] GetBytes(this string str)
{ {
return str.GetBytes(Encoding.UTF8); return str.GetBytes(Encoding.UTF8);
} }
/// <summary> /// <summary>
/// Gets a <see cref="byte"/>[] representing the value the <see cref="string"/> with the provided encoding. /// Gets a <see cref="byte" />[] representing the value the <see cref="string" /> with the provided encoding.
/// </summary> /// </summary>
/// <param name="str">The string to convert.</param> /// <param name="str">The string to convert.</param>
/// <param name="encoding">The encoding to use.</param> /// <param name="encoding">The encoding to use.</param>
/// <returns>Returns a <see cref="byte"/>[].</returns> /// <returns>Returns a <see cref="byte" />[].</returns>
/// <exception cref="ArgumentNullException"><paramref name="str"/> or <paramref name="encoding"/> or both are /// <exception cref="ArgumentNullException">
/// <see langword="null"/>.</exception> /// <paramref name="str" /> or <paramref name="encoding" /> or both are
/// <see langword="null" />.
/// </exception>
public static byte[] GetBytes(this string str, Encoding encoding) public static byte[] GetBytes(this string str, Encoding encoding)
{ {
if (str is null) if (str is null)
@ -149,8 +159,10 @@
/// Determines if all alpha characters in this string are considered lowercase. /// Determines if all alpha characters in this string are considered lowercase.
/// </summary> /// </summary>
/// <param name="str">The input string.</param> /// <param name="str">The input string.</param>
/// <returns>Returns <see langword="true"/> if all alpha characters are lowercase, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if all alpha characters are lowercase, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsLower(this string str) public static bool IsLower(this string str)
{ {
return str.Where(char.IsLetter).All(char.IsLower); return str.Where(char.IsLetter).All(char.IsLower);
@ -160,32 +172,34 @@
/// Determines if all alpha characters in this string are considered uppercase. /// Determines if all alpha characters in this string are considered uppercase.
/// </summary> /// </summary>
/// <param name="str">The input string.</param> /// <param name="str">The input string.</param>
/// <returns>Returns <see langword="true"/> if all alpha characters are uppercase, <see langword="false"/> /// <returns>
/// otherwise.</returns> /// Returns <see langword="true" /> if all alpha characters are uppercase, <see langword="false" />
/// otherwise.
/// </returns>
public static bool IsUpper(this string str) public static bool IsUpper(this string str)
{ {
return str.Where(char.IsLetter).All(char.IsUpper); return str.Where(char.IsLetter).All(char.IsUpper);
} }
/// <summary> /// <summary>
/// Generates a new random string by filling it with characters found in <see cref="str"/>. /// Generates a new random string by filling it with characters found in <see cref="str" />.
/// </summary> /// </summary>
/// <param name="str">The character set.</param> /// <param name="str">The character set.</param>
/// <param name="length">The length of the string to generate.</param> /// <param name="length">The length of the string to generate.</param>
/// <returns>Returns a <see cref="string"/> containing <paramref name="length"/> characters.</returns> /// <returns>Returns a <see cref="string" /> containing <paramref name="length" /> characters.</returns>
public static string Random(this string str, int length) public static string Random(this string str, int length)
{ {
return str.Random(length, RandomExtensions.Random); return str.Random(length, RandomExtensions.Random);
} }
/// <summary> /// <summary>
/// Generates a new random string by filling it with characters found in <see cref="str"/>. /// Generates a new random string by filling it with characters found in <see cref="str" />.
/// </summary> /// </summary>
/// <param name="str">The character set.</param> /// <param name="str">The character set.</param>
/// <param name="length">The length of the string to generate.</param> /// <param name="length">The length of the string to generate.</param>
/// <param name="random">The <see cref="System.Random"/> instance.</param> /// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <returns>Returns a <see cref="string"/> containing <paramref name="length"/> characters.</returns> /// <returns>Returns a <see cref="string" /> containing <paramref name="length" /> characters.</returns>
/// <exception cref="ArgumentNullException"><paramref name="str"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="str" /> is <see langword="null" />.</exception>
public static string Random(this string str, int length, Random random) public static string Random(this string str, int length, Random random)
{ {
if (str is null) if (str is null)
@ -201,9 +215,11 @@
/// </summary> /// </summary>
/// <param name="str">The string to repeat.</param> /// <param name="str">The string to repeat.</param>
/// <param name="count">The repeat count.</param> /// <param name="count">The repeat count.</param>
/// <returns>Returns a <see cref="string"/> whose value is <paramref name="str"/> repeated /// <returns>
/// <paramref name="count"/> times.</returns> /// Returns a <see cref="string" /> whose value is <paramref name="str" /> repeated
/// <exception cref="ArgumentNullException"><paramref name="str"/> is <see langword="null"/>.</exception> /// <paramref name="count" /> times.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="str" /> is <see langword="null" />.</exception>
public static string Repeat(this string str, int count) public static string Repeat(this string str, int count)
{ {
if (str is null) if (str is null)
@ -225,7 +241,7 @@
/// Shuffles the characters in the string. /// Shuffles the characters in the string.
/// </summary> /// </summary>
/// <param name="str">The string to shuffle.</param> /// <param name="str">The string to shuffle.</param>
/// <returns>Returns a <see cref="string"/> containing the characters in <paramref name="str"/>, rearranged.</returns> /// <returns>Returns a <see cref="string" /> containing the characters in <paramref name="str" />, rearranged.</returns>
public static string Shuffle(this string str) public static string Shuffle(this string str)
{ {
return str.Shuffle(RandomExtensions.Random); return str.Shuffle(RandomExtensions.Random);
@ -235,9 +251,9 @@
/// Shuffles the characters in the string. /// Shuffles the characters in the string.
/// </summary> /// </summary>
/// <param name="str">The string to shuffle.</param> /// <param name="str">The string to shuffle.</param>
/// <param name="random">The <see cref="System.Random"/> instance.</param> /// <param name="random">The <see cref="System.Random" /> instance.</param>
/// <returns>Returns a <see cref="string"/> containing the characters in <paramref name="str"/>, rearranged.</returns> /// <returns>Returns a <see cref="string" /> containing the characters in <paramref name="str" />, rearranged.</returns>
/// <exception cref="ArgumentNullException"><paramref name="str"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="str" /> is <see langword="null" />.</exception>
public static string Shuffle(this string str, Random random) public static string Shuffle(this string str, Random random)
{ {
if (str is null) if (str is null)
@ -249,13 +265,15 @@
} }
/// <summary> /// <summary>
/// Splits the <see cref="string"/> into chunks that are no greater than <paramref name="chunkSize"/> in length. /// Splits the <see cref="string" /> into chunks that are no greater than <paramref name="chunkSize" /> in length.
/// </summary> /// </summary>
/// <param name="str">The string to split.</param> /// <param name="str">The string to split.</param>
/// <param name="chunkSize">The maximum length of each string in the returned result.</param> /// <param name="chunkSize">The maximum length of each string in the returned result.</param>
/// <returns>Returns an <see cref="IEnumerable{T}"/> containing <see cref="string"/> instances which are no /// <returns>
/// greater than <paramref name="chunkSize"/> in length.</returns> /// Returns an <see cref="IEnumerable{T}" /> containing <see cref="string" /> instances which are no
/// <exception cref="ArgumentNullException"><paramref name="str"/> is <see langword="null"/>.</exception> /// greater than <paramref name="chunkSize" /> in length.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="str" /> is <see langword="null" />.</exception>
public static IEnumerable<string> Split(this string str, int chunkSize) public static IEnumerable<string> Split(this string str, int chunkSize)
{ {
if (str is null) if (str is null)
@ -275,11 +293,11 @@
} }
/// <summary> /// <summary>
/// Converts a <see cref="string"/> to a <see cref="SecureString"/>. /// Converts a <see cref="string" /> to a <see cref="SecureString" />.
/// </summary> /// </summary>
/// <param name="str">The string to convert.</param> /// <param name="str">The string to convert.</param>
/// <returns>Returns a <see cref="SecureString"/>.</returns> /// <returns>Returns a <see cref="SecureString" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="str"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="str" /> is <see langword="null" />.</exception>
public static SecureString ToSecureString(this string str) public static SecureString ToSecureString(this string str)
{ {
if (str is null) if (str is null)
@ -302,12 +320,12 @@
} }
/// <summary> /// <summary>
/// Converts a <see cref="SecureString"/> to a <see cref="string"/>. /// Converts a <see cref="SecureString" /> to a <see cref="string" />.
/// </summary> /// </summary>
/// <param name="str">The <see cref="SecureString"/> to convert.</param> /// <param name="str">The <see cref="SecureString" /> to convert.</param>
/// <param name="extension">Whether or not to use this extension method.</param> /// <param name="extension">Whether or not to use this extension method.</param>
/// <returns>Returns a <see cref="string"/>.</returns> /// <returns>Returns a <see cref="string" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="str"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="str" /> is <see langword="null" />.</exception>
public static string ToString(this SecureString str, bool extension) public static string ToString(this SecureString str, bool extension)
{ {
if (str is null) if (str is null)
@ -320,11 +338,11 @@
/// <summary> /// <summary>
/// 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
/// <see cref="TimeSpan"/>. /// <see cref="TimeSpan" />.
/// </summary> /// </summary>
/// <param name="str">The input string.</param> /// <param name="str">The input string.</param>
/// <returns>Returns an instance of <see cref="TimeSpan"/>.</returns> /// <returns>Returns an instance of <see cref="TimeSpan" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="str"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="str" /> is <see langword="null" />.</exception>
public static TimeSpan ToTimeSpan(this string str) public static TimeSpan ToTimeSpan(this string str)
{ {
if (str is null) if (str is null)

View File

@ -3,18 +3,20 @@
using System; using System;
/// <summary> /// <summary>
/// Extension methods for <see langword="struct"/> types. /// Extension methods for <see langword="struct" /> types.
/// </summary> /// </summary>
public static class StructExtensions public static class StructExtensions
{ {
/// <summary> /// <summary>
/// Returns the next value in an <see cref="Enum"/> using the specified value as a starting point. /// Returns the next value in an <see cref="Enum" /> using the specified value as a starting point.
/// </summary> /// </summary>
/// <typeparam name="T">An <see cref="Enum"/>.</typeparam> /// <typeparam name="T">An <see cref="Enum" />.</typeparam>
/// <param name="src">An <see cref="Enum"/> value.</param> /// <param name="src">An <see cref="Enum" /> value.</param>
/// <param name="wrap">Optional. Whether or not to wrap to the to the start of the enum. Defaults to /// <param name="wrap">
/// true.</param> /// Optional. Whether or not to wrap to the to the start of the enum. Defaults to
/// <returns>Returns a <see cref="T"/> value.</returns> /// true.
/// </param>
/// <returns>Returns a <see cref="T" /> value.</returns>
public static T Next<T>(this T src, bool wrap = true) public static T Next<T>(this T src, bool wrap = true)
where T : struct where T : struct
{ {
@ -29,13 +31,15 @@
} }
/// <summary> /// <summary>
/// Returns the previous value in an <see cref="Enum"/> using the specified value as a starting point. /// Returns the previous value in an <see cref="Enum" /> using the specified value as a starting point.
/// </summary> /// </summary>
/// <typeparam name="T">An <see cref="Enum"/>.</typeparam> /// <typeparam name="T">An <see cref="Enum" />.</typeparam>
/// <param name="src">An <see cref="Enum"/> value.</param> /// <param name="src">An <see cref="Enum" /> value.</param>
/// <param name="wrap">Optional. Whether or not to wrap to the to the end of the enum. Defaults to /// <param name="wrap">
/// true.</param> /// Optional. Whether or not to wrap to the to the end of the enum. Defaults to
/// <returns>Returns a <see cref="T"/> value.</returns> /// true.
/// </param>
/// <returns>Returns a <see cref="T" /> value.</returns>
public static T Previous<T>(this T src, bool wrap = true) public static T Previous<T>(this T src, bool wrap = true)
where T : struct where T : struct
{ {

View File

@ -5,17 +5,17 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
/// <summary> /// <summary>
/// Represents a class which contains a <see cref="string"/> parser which converts into <see cref="TimeSpan"/>. /// Represents a class which contains a <see cref="string" /> parser which converts into <see cref="TimeSpan" />.
/// </summary> /// </summary>
public static class TimeSpanParser public static class TimeSpanParser
{ {
/// <summary> /// <summary>
/// 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
/// <see cref="TimeSpan"/>. /// <see cref="TimeSpan" />.
/// </summary> /// </summary>
/// <param name="input">The input string.</param> /// <param name="input">The input string.</param>
/// <param name="provider">The format provider.</param> /// <param name="provider">The format provider.</param>
/// <returns>Returns an instance of <see cref="TimeSpan"/>.</returns> /// <returns>Returns an instance of <see cref="TimeSpan" />.</returns>
public static TimeSpan Parse(string input, IFormatProvider provider = null) public static TimeSpan Parse(string input, IFormatProvider provider = null)
{ {
const string realNumberPattern = @"([0-9]*\.[0-9]+|[0-9]+)"; const string realNumberPattern = @"([0-9]*\.[0-9]+|[0-9]+)";
@ -26,7 +26,7 @@
$"(?:{realNumberPattern} *s)? *" + $"(?:{realNumberPattern} *s)? *" +
$"(?:{realNumberPattern} *ms)?$"; $"(?:{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; double weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0, milliseconds = 0;
if (match.Groups[1].Success) if (match.Groups[1].Success)
@ -62,7 +62,7 @@
Trace.WriteLine($"Input: {input}"); Trace.WriteLine($"Input: {input}");
Trace.WriteLine($"Parsed: {weeks}w {days}d {hours}h {minutes}m {seconds}s {milliseconds}ms"); 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(weeks * 7);
span += TimeSpan.FromDays(days); span += TimeSpan.FromDays(days);