summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModRegistry.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/ModRegistry.cs')
-rw-r--r--src/SMAPI/Framework/ModRegistry.cs34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/SMAPI/Framework/ModRegistry.cs b/src/SMAPI/Framework/ModRegistry.cs
index cae38637..1ae5643f 100644
--- a/src/SMAPI/Framework/ModRegistry.cs
+++ b/src/SMAPI/Framework/ModRegistry.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -37,12 +35,12 @@ namespace StardewModdingAPI.Framework
this.Mods.Add(metadata);
}
- /// <summary>Track a mod's assembly for use via <see cref="GetFrom"/>.</summary>
+ /// <summary>Track a mod's assembly for use via <see cref="GetFrom(Type?)"/>.</summary>
/// <param name="metadata">The mod metadata.</param>
/// <param name="modAssembly">The mod assembly.</param>
public void TrackAssemblies(IModMetadata metadata, Assembly modAssembly)
{
- this.ModNamesByAssembly[modAssembly.FullName] = metadata;
+ this.ModNamesByAssembly[modAssembly.FullName!] = metadata;
}
/// <summary>Get metadata for all loaded mods.</summary>
@@ -61,8 +59,8 @@ namespace StardewModdingAPI.Framework
/// <summary>Get metadata for a loaded mod.</summary>
/// <param name="uniqueID">The mod's unique ID.</param>
- /// <returns>Returns the matching mod's metadata, or <c>null</c> if not found.</returns>
- public IModMetadata Get(string uniqueID)
+ /// <returns>Returns the mod's metadata, or <c>null</c> if not found.</returns>
+ public IModMetadata? Get(string uniqueID)
{
// normalize search ID
if (string.IsNullOrWhiteSpace(uniqueID))
@@ -75,15 +73,15 @@ namespace StardewModdingAPI.Framework
/// <summary>Get the mod metadata from one of its assemblies.</summary>
/// <param name="type">The type to check.</param>
- /// <returns>Returns the mod name, or <c>null</c> if the type isn't part of a known mod.</returns>
- public IModMetadata GetFrom(Type type)
+ /// <returns>Returns the mod's metadata, or <c>null</c> if the type isn't part of a known mod.</returns>
+ public IModMetadata? GetFrom(Type? type)
{
// null
if (type == null)
return null;
// known type
- string assemblyName = type.Assembly.FullName;
+ string assemblyName = type.Assembly.FullName!;
if (this.ModNamesByAssembly.ContainsKey(assemblyName))
return this.ModNamesByAssembly[assemblyName];
@@ -91,9 +89,18 @@ namespace StardewModdingAPI.Framework
return null;
}
- /// <summary>Get the friendly name for the closest assembly registered as a source of deprecation warnings.</summary>
- /// <returns>Returns the source name, or <c>null</c> if no registered assemblies were found.</returns>
- public IModMetadata GetFromStack()
+ /// <summary>Get the mod metadata from a stack frame, if any.</summary>
+ /// <param name="frame">The stack frame to check.</param>
+ /// <returns>Returns the mod's metadata, or <c>null</c> if the frame isn't part of a known mod.</returns>
+ public IModMetadata? GetFrom(StackFrame frame)
+ {
+ MethodBase? method = frame.GetMethod();
+ return this.GetFrom(method?.ReflectedType);
+ }
+
+ /// <summary>Get the mod metadata from the closest assembly registered as a source of deprecation warnings.</summary>
+ /// <returns>Returns the mod's metadata, or <c>null</c> if no registered assemblies were found.</returns>
+ public IModMetadata? GetFromStack()
{
// get stack frames
StackTrace stack = new();
@@ -102,8 +109,7 @@ namespace StardewModdingAPI.Framework
// search stack for a source assembly
foreach (StackFrame frame in frames)
{
- MethodBase method = frame.GetMethod();
- IModMetadata mod = this.GetFrom(method.ReflectedType);
+ IModMetadata? mod = this.GetFrom(frame);
if (mod != null)
return mod;
}