summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/ModRegistry.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-01-16 16:10:57 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-01-16 16:10:57 -0500
commit6adf199987a506f8a65f6c1ddfad5aa9fa2a6a9f (patch)
treefaa9155fae99533110853567003325486f208937 /src/StardewModdingAPI/Framework/ModRegistry.cs
parente8825947ca82c8f28ad9bc8a225fb4fb749814cb (diff)
parent1f3d3c8c93c7a427486b60cf649b86cef140e88b (diff)
downloadSMAPI-6adf199987a506f8a65f6c1ddfad5aa9fa2a6a9f.tar.gz
SMAPI-6adf199987a506f8a65f6c1ddfad5aa9fa2a6a9f.tar.bz2
SMAPI-6adf199987a506f8a65f6c1ddfad5aa9fa2a6a9f.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/StardewModdingAPI/Framework/ModRegistry.cs')
-rw-r--r--src/StardewModdingAPI/Framework/ModRegistry.cs40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/StardewModdingAPI/Framework/ModRegistry.cs b/src/StardewModdingAPI/Framework/ModRegistry.cs
index b593142d..51ec7123 100644
--- a/src/StardewModdingAPI/Framework/ModRegistry.cs
+++ b/src/StardewModdingAPI/Framework/ModRegistry.cs
@@ -36,6 +36,34 @@ namespace StardewModdingAPI.Framework
return (from mod in this.Mods select mod);
}
+ /// <summary>Get the friendly mod name which handles a delegate.</summary>
+ /// <param name="delegate">The delegate to follow.</param>
+ /// <returns>Returns the mod name, or <c>null</c> if the delegate isn't implemented by a known mod.</returns>
+ public string GetModFrom(Delegate @delegate)
+ {
+ return @delegate?.Target != null
+ ? this.GetModFrom(@delegate.Target.GetType())
+ : null;
+ }
+
+ /// <summary>Get the friendly mod name which defines a type.</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 string GetModFrom(Type type)
+ {
+ // null
+ if (type == null)
+ return null;
+
+ // known type
+ string assemblyName = type.Assembly.FullName;
+ if (this.ModNamesByAssembly.ContainsKey(assemblyName))
+ return this.ModNamesByAssembly[assemblyName];
+
+ // not found
+ 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 string GetModFromStack()
@@ -49,16 +77,10 @@ namespace StardewModdingAPI.Framework
// search stack for a source assembly
foreach (StackFrame frame in frames)
{
- // get assembly name
MethodBase method = frame.GetMethod();
- Type type = method.ReflectedType;
- if (type == null)
- continue;
- string assemblyName = type.Assembly.FullName;
-
- // get name if it's a registered source
- if (this.ModNamesByAssembly.ContainsKey(assemblyName))
- return this.ModNamesByAssembly[assemblyName];
+ string name = this.GetModFrom(method.ReflectedType);
+ if (name != null)
+ return name;
}
// no known assembly found