mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 15:12:57 +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)
|
private void placeComponent(Type type)
|
||||||
{
|
{
|
||||||
var instance = (Drawable)Activator.CreateInstance(type) as ISkinnableComponent;
|
if (!(Activator.CreateInstance(type) is ISkinnableComponent component))
|
||||||
|
|
||||||
if (instance == null)
|
|
||||||
throw new InvalidOperationException("Attempted to instantiate a component for placement which was not an {typeof(ISkinnableComponent)}.");
|
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.Clear();
|
||||||
SelectedComponents.Add(instance);
|
SelectedComponents.Add(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ISkinnableTarget getTarget(SkinnableTarget target)
|
private ISkinnableTarget getTarget(SkinnableTarget target)
|
||||||
|
Loading…
Reference in New Issue
Block a user