-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update code style for C#, and codify it in the eidtor config file.
- Loading branch information
1 parent
61bdb25
commit 5e53828
Showing
23 changed files
with
1,186 additions
and
1,171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()}"); | ||
} | ||
} |
Oops, something went wrong.