Skip to content

Commit

Permalink
.editorconfig Improvements
Browse files Browse the repository at this point in the history
Update code style for C#, and codify it in the eidtor config file.
  • Loading branch information
iwillspeak committed Jun 22, 2024
1 parent 61bdb25 commit 5e53828
Show file tree
Hide file tree
Showing 23 changed files with 1,186 additions and 1,171 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ indent_style = space
[*.cs]
indent_style = space
indent_size = 4
dotnet_separate_import_directive_groups = true
dotnet_sort_system_directives_first = true
dotnet_style_qualification_for_event = false
dotnet_style_qualification_for_field = false
dotnet_style_qualification_for_method = false
dotnet_style_qualification_for_property = false
dotnet_style_predefined_type_for_locals_parameters_members = true
dotnet_style_predefined_type_for_member_access = true
dotnet_style_require_accessibility_modifiers = for_non_interface_members
dotnet_style_operator_placement_when_wrapping = end_of_line
dotnet_style_allow_multiple_blank_lines_experimental = true
dotnet_style_allow_statement_immediately_after_block_experimental = false
csharp_style_namespace_declarations = file_scoped

[*.json]
indent_style = space
Expand Down
105 changes: 52 additions & 53 deletions src/Serehfa/ArgHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,76 +1,75 @@
using System;

namespace Serehfa
namespace Serehfa;

public class ArgHelpers
{
public class ArgHelpers
public static void CheckNoArgs(object[] args)
{
public static void CheckNoArgs(object[] args)
if (args.Length != 0)
{
if (args.Length != 0)
{
throw new ArgumentException(
$"Expected no arguments, but received {args.Length}",
nameof(args));
}
throw new ArgumentException(
$"Expected no arguments, but received {args.Length}",
nameof(args));
}
}

public static void CheckAtLeastArgs(object[] args, int count)
public static void CheckAtLeastArgs(object[] args, int count)
{
if (args.Length < count)
{
if (args.Length < count)
{
throw new ArgumentException(
$"Expected at least {count} arguments, but received {args.Length}",
nameof(args));
}
throw new ArgumentException(
$"Expected at least {count} arguments, but received {args.Length}",
nameof(args));
}
}

public static T UnpackArgs<T>(object[] args)
public static T UnpackArgs<T>(object[] args)
{
if (args.Length != 1)
{
if (args.Length != 1)
{
throw new ArgumentException(
$"Expected 1 arg, but found {args.Length}",
nameof(args));
}

return Unpack<T>(args[0]);
throw new ArgumentException(
$"Expected 1 arg, but found {args.Length}",
nameof(args));
}

public static (T, U) UnpackArgs<T, U>(object[] args)
{
if (args.Length != 2)
{
throw new ArgumentException(
$"Expected 2 args, but found {args.Length}",
nameof(args));
}
return Unpack<T>(args[0]);
}

return (Unpack<T>(args[0]), Unpack<U>(args[1]));
public static (T, U) UnpackArgs<T, U>(object[] args)
{
if (args.Length != 2)
{
throw new ArgumentException(
$"Expected 2 args, but found {args.Length}",
nameof(args));
}

public static (T, U, V) UnpackArgs<T, U, V>(object[] args)
{
if (args.Length != 3)
{
throw new ArgumentException(
$"Expected 3 args, but found {args.Length}",
nameof(args));
}
return (Unpack<T>(args[0]), Unpack<U>(args[1]));
}

return (Unpack<T>(args[0]), Unpack<U>(args[1]), Unpack<V>(args[2]));
public static (T, U, V) UnpackArgs<T, U, V>(object[] args)
{
if (args.Length != 3)
{
throw new ArgumentException(
$"Expected 3 args, but found {args.Length}",
nameof(args));
}

public static T Unpack<T>(object arg)
return (Unpack<T>(args[0]), Unpack<U>(args[1]), Unpack<V>(args[2]));
}

public static T Unpack<T>(object arg)
{
if (arg is null)
{
return default;
}
if (arg is T converted)
{
if (arg is null)
{
return default;
}
if (arg is T converted)
{
return converted;
}
throw new ArgumentException($"Expected {typeof(T)}, but found {arg?.GetType()}");
return converted;
}
throw new ArgumentException($"Expected {typeof(T)}, but found {arg?.GetType()}");
}
}
Loading

0 comments on commit 5e53828

Please sign in to comment.