Remove `ServiceInjector.ClearServices`

This call in `ToolManager.Restart` was to set `[{Optional.Required}Service]`
props to `null`, but the tool form would get `Close`d immediately afterwards, so
it never gets the chance to hit the `null` path if one exists. However, some
tools are written as though they keep the stale value, for example attempting to
call a cleanup function on it in their `Closed` event handler. These will now
work as intended.
`[OptionalService]`s that can't be satisfied are set to `null` by
`ServiceInjector.UpdateServices`, so clearing those isn't necessary, and
`ClearServices` has no other usages.
This commit is contained in:
YoshiRulz 2023-04-13 04:14:19 +10:00
parent ddc3e929e9
commit 5f77a310c5
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 0 additions and 17 deletions

View File

@ -598,7 +598,6 @@ namespace BizHawk.Client.EmuHawk
else
{
unavailable.Add(tool);
ServiceInjector.ClearServices(tool); // the services of the old emulator core are no longer valid on the tool
if (tool is IExternalToolForm) ApiInjector.ClearApis(tool);
}
}

View File

@ -10,22 +10,6 @@ namespace BizHawk.Emulation.Common
/// </summary>
public static class ServiceInjector
{
/// <summary>
/// clears all services from a target
/// </summary>
public static void ClearServices(object target)
{
Type targetType = target.GetType();
object?[] tmp = { null };
foreach (var propInfo in
targetType.GetPropertiesWithAttrib(typeof(RequiredServiceAttribute))
.Concat(targetType.GetPropertiesWithAttrib(typeof(OptionalServiceAttribute))))
{
propInfo.GetSetMethod(true).Invoke(target, tmp);
}
}
/// <summary>
/// Feeds the target its required services.
/// </summary>