Skip to content

Commit

Permalink
Use collection expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Emik03 committed Feb 13, 2024
1 parent 25c3957 commit ded3250
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
5 changes: 2 additions & 3 deletions wawa.Modules/Source/Sounds/Sound.EffectTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ public sealed partial class Sound
/// <summary>Gets all vanilla sounds from the base game.</summary>
[NotNull, PublicAPI]
public static ReadOnlyCollection<Sound> Vanillas { [Pure] get; } = new(
new[]
{
[
AlarmClockBeep,
AlarmClockSnooze,
BigButtonPress,
Expand Down Expand Up @@ -37,7 +36,7 @@ public sealed partial class Sound
TypewriterKey,
WireSequenceMechanism,
WireSnip,
}
]
);
/// <summary>Gets the sound that plays when the alarm clock goes off. This sound loops.</summary>
Expand Down
5 changes: 1 addition & 4 deletions wawa.Recall/Source/Abstractions/Domains/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ static readonly MethodInfo
s_combine = ((Func<Delegate, Delegate, Delegate>)Delegate.Combine).Method,
s_remove = ((Delegate)Delegate.Remove).Method;

[NotNull]
static readonly ParameterExpression[] s_parameterless = new ParameterExpression[0];

/// <inheritdoc cref="TrySet{T}(Hook{T}, T)"/>
[PublicAPI]
public static bool TrySet<T>(
Expand Down Expand Up @@ -530,7 +527,7 @@ static Func<T, Delegate> Caster<T>([NotNull] this Type type)
var exParameter = Expression.Parameter(typeof(T), nameof(T));
var method = type.GetMethod(nameof(Action.Invoke))!;
var exArgs = method.GetParameters().Select((x, i) => Expression.Parameter(x.ParameterType, $"a{i}")).ToArray();
var exDest = typeof(T).GetMethod(nameof(Action.Invoke))!.GetParameters().Length is 0 ? s_parameterless : exArgs;
var exDest = typeof(T).GetMethod(nameof(Action.Invoke))!.GetParameters().Length is 0 ? [] : exArgs;
var exInvoke = Expression.Invoke(exParameter, exDest.Cast<Expression>());
var exLambda = Expression.Lambda(type, exInvoke, exArgs);
var exIsNull = Expression.Equal(exParameter, exNull);
Expand Down
2 changes: 1 addition & 1 deletion wawa.Recall/Source/Internals/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class Lot<T>
public static Func<T, T> Id => x => x;

/// <summary>Gets the empty set.</summary>
public static ReadOnlyCollection<T> Empty { [Pure] get; } = new(new T[0]);
public static ReadOnlyCollection<T> Empty { [Pure] get; } = new([]);
}

/// <summary>Gets the <see cref="AssemblyName"/> of the caller that invoked the method calling this.</summary>
Expand Down
2 changes: 1 addition & 1 deletion wawa.TwitchPlays/Source/Domains/Instruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Instruction([ItemCanBeNull, NotNull] IEnumerable<Instruction> enumerator)
/// For the camera side view. The second one in the form of <c>Quaternion.Euler(x, y, z)</c>.
/// </param>
[CLSCompliant(false), PublicAPI]
public Instruction(Quaternion first, Quaternion second) => Value = new[] { first, second };
public Instruction(Quaternion first, Quaternion second) => Value = (Quaternion[])[first, second];

/// <summary>Initializes a new instance of the <see cref="Instruction"/> class.</summary>
/// <param name="value">The value to pass in.</param>
Expand Down
10 changes: 4 additions & 6 deletions wawa.TwitchPlays/Source/Twitch{TMod}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,14 @@ object Field() =>
if (type == typeof(string) || type == typeof(object))
return value;

var arr = new[] { typeof(string), type.MakeByRefType() };
Type[] signature = [typeof(string), type.MakeByRefType()];

if (type.GetMethod(nameof(int.TryParse), arr) is not { IsStatic: true } method ||
if (type.GetMethod(nameof(int.TryParse), signature) is not { IsStatic: true } method ||
method.ReturnType != typeof(bool))
return Field();

var args = new object[] { value, null };
var ret = (bool)method.Invoke(null, args);

return ret ? args[1] : ParseError.NoMatch;
object[] args = [value, null];
return method.Invoke(null, args) is true ? args[1] : ParseError.NoMatch;
}

[ItemNotNull, NotNull]
Expand Down

0 comments on commit ded3250

Please sign in to comment.