Skip to content

Commit

Permalink
Inline condition
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Sep 25, 2024
1 parent fd4891c commit 2fe229d
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions osu.Game/Utils/BindableValueAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static class BindableValueAccessor

public static object GetValue(IBindable bindable)
{
Type? bindableWithValueType = bindable.GetType().GetInterfaces().FirstOrDefault(isBindableT);
Type? bindableWithValueType = bindable.GetType().GetInterfaces().FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IBindable<>));
if (bindableWithValueType == null)
return bindable;

Expand All @@ -25,18 +25,13 @@ public static object GetValue(IBindable bindable)

public static void SetValue(IBindable bindable, object value)
{
Type? bindableWithValueType = bindable.GetType().EnumerateBaseTypes().FirstOrDefault(isBindableT);
Type? bindableWithValueType = bindable.GetType().EnumerateBaseTypes().SingleOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Bindable<>));
if (bindableWithValueType == null)
return;

set_method.MakeGenericMethod(bindableWithValueType.GenericTypeArguments[0]).Invoke(null, [bindable, value]);
}

private static bool isBindableT(Type type)
=> type.IsGenericType
&& (type.GetGenericTypeDefinition() == typeof(Bindable<>)
|| type.GetGenericTypeDefinition() == typeof(IBindable<>));

private static object getValue<T>(object bindable) => ((IBindable<T>)bindable).Value!;

private static object setValue<T>(object bindable, object value) => ((Bindable<T>)bindable).Value = (T)value;
Expand Down

0 comments on commit 2fe229d

Please sign in to comment.