1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 00:02:54 +08:00

Use pattern matching to tidy up instance construction

This commit is contained in:
Dean Herbert 2021-05-12 14:02:20 +09:00
parent 4aad7b96ea
commit 96d4011de2

View File

@ -166,15 +166,13 @@ namespace osu.Game.Skinning.Editor
private void placeComponent(Type type)
{
var instance = (Drawable)Activator.CreateInstance(type) as ISkinnableComponent;
if (instance == null)
if (!(Activator.CreateInstance(type) is ISkinnableComponent component))
throw new InvalidOperationException("Attempted to instantiate a component for placement which was not an {typeof(ISkinnableComponent)}.");
getTarget(SkinnableTarget.MainHUDComponents)?.Add(instance);
getTarget(SkinnableTarget.MainHUDComponents)?.Add(component);
SelectedComponents.Clear();
SelectedComponents.Add(instance);
SelectedComponents.Add(component);
}
private ISkinnableTarget getTarget(SkinnableTarget target)