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:
parent
4aad7b96ea
commit
96d4011de2
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user