mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Remove nullability of Ruleset.CreateInstance
This commit is contained in:
parent
216c18b0bb
commit
8d69ebd7db
@ -60,5 +60,27 @@ namespace osu.Game.Models
|
||||
InstantiationInfo = InstantiationInfo,
|
||||
Available = Available
|
||||
};
|
||||
|
||||
public Ruleset CreateInstance()
|
||||
{
|
||||
if (!Available)
|
||||
throw new RulesetLoadException(@"Ruleset not available");
|
||||
|
||||
var type = Type.GetType(InstantiationInfo);
|
||||
|
||||
if (type == null)
|
||||
throw new RulesetLoadException(@"Type lookup failure");
|
||||
|
||||
var ruleset = Activator.CreateInstance(type) as Ruleset;
|
||||
|
||||
if (ruleset == null)
|
||||
throw new RulesetLoadException(@"Instantiation failure");
|
||||
|
||||
// overwrite the pre-populated RulesetInfo with a potentially database attached copy.
|
||||
// TODO: figure if we still want/need this after switching to realm.
|
||||
// ruleset.RulesetInfo = this;
|
||||
|
||||
return ruleset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using osu.Game.Database;
|
||||
|
||||
#nullable enable
|
||||
@ -28,20 +27,6 @@ namespace osu.Game.Rulesets
|
||||
/// </summary>
|
||||
string InstantiationInfo { get; }
|
||||
|
||||
Ruleset? CreateInstance()
|
||||
{
|
||||
var type = Type.GetType(InstantiationInfo);
|
||||
|
||||
if (type == null)
|
||||
return null;
|
||||
|
||||
var ruleset = Activator.CreateInstance(type) as Ruleset;
|
||||
|
||||
// overwrite the pre-populated RulesetInfo with a potentially database attached copy.
|
||||
// TODO: figure if we still want/need this after switching to realm.
|
||||
// ruleset.RulesetInfo = this;
|
||||
|
||||
return ruleset;
|
||||
}
|
||||
Ruleset CreateInstance();
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Testing;
|
||||
|
||||
namespace osu.Game.Rulesets
|
||||
@ -26,9 +25,18 @@ namespace osu.Game.Rulesets
|
||||
// TODO: this should probably be moved to RulesetStore.
|
||||
public Ruleset CreateInstance()
|
||||
{
|
||||
if (!Available) return null;
|
||||
if (!Available)
|
||||
throw new RulesetLoadException(@"Ruleset not available");
|
||||
|
||||
var ruleset = (Ruleset)Activator.CreateInstance(Type.GetType(InstantiationInfo).AsNonNull());
|
||||
var type = Type.GetType(InstantiationInfo);
|
||||
|
||||
if (type == null)
|
||||
throw new RulesetLoadException(@"Type lookup failure");
|
||||
|
||||
var ruleset = Activator.CreateInstance(type) as Ruleset;
|
||||
|
||||
if (ruleset == null)
|
||||
throw new RulesetLoadException(@"Instantiation failure");
|
||||
|
||||
// overwrite the pre-populated RulesetInfo with a potentially database attached copy.
|
||||
ruleset.RulesetInfo = this;
|
||||
|
Loading…
Reference in New Issue
Block a user