1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:17:26 +08:00

Change CreateInstance to use Activator.CreateInstance instead of clone

This commit is contained in:
Dean Herbert 2021-09-10 12:05:10 +09:00
parent 9cf79a80c2
commit 719392de39
2 changed files with 3 additions and 13 deletions

View File

@ -27,6 +27,6 @@ namespace osu.Game.Rulesets.Mods
/// <summary>
/// Create a fresh <see cref="Mod"/> instance based on this mod.
/// </summary>
Mod CreateInstance() => ((Mod)this).DeepClone();
Mod CreateInstance() => (Mod)Activator.CreateInstance(GetType());
}
}

View File

@ -80,12 +80,7 @@ namespace osu.Game.Rulesets
/// <param name="acronym">The acronym to query for .</param>
public Mod CreateModFromAcronym(string acronym)
{
var type = AllMods.FirstOrDefault(m => m.Acronym == acronym)?.GetType();
if (type != null)
return (Mod)Activator.CreateInstance(type);
return null;
return AllMods.FirstOrDefault(m => m.Acronym == acronym)?.CreateInstance();
}
/// <summary>
@ -94,12 +89,7 @@ namespace osu.Game.Rulesets
public T CreateMod<T>()
where T : Mod
{
var type = AllMods.FirstOrDefault(m => m is T)?.GetType();
if (type != null)
return (T)Activator.CreateInstance(type);
return null;
return AllMods.FirstOrDefault(m => m is T)?.CreateInstance() as T;
}
public abstract IEnumerable<Mod> GetModsFor(ModType type);