Changes

Jump to navigation Jump to search
expand API known limitations
Line 56: Line 56:  
* Be careful when changing your API! If you make a breaking change, other mods may need an update before they can access your API again.
 
* Be careful when changing your API! If you make a breaking change, other mods may need an update before they can access your API again.
 
* You can optionally add a public [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface interface] to your API. If a mod directly references your mod DLL, they'll be able to use your interface instead of creating their own.
 
* You can optionally add a public [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface interface] to your API. If a mod directly references your mod DLL, they'll be able to use your interface instead of creating their own.
* '''Known issue:''' SMAPI doesn't currently support non-public API classes.
      
===Using an API===
 
===Using an API===
Line 86: Line 85:  
* You can't call <tt>GetApi</tt> until all mods are initialised and their <tt>Entry</tt> methods called. You can use the <tt>GameLoop.GameLaunched</tt> [[#Events|event]] if you need to access mod APIs early; this is guaranteed to happen after all mods are initialised.
 
* You can't call <tt>GetApi</tt> until all mods are initialised and their <tt>Entry</tt> methods called. You can use the <tt>GameLoop.GameLaunched</tt> [[#Events|event]] if you need to access mod APIs early; this is guaranteed to happen after all mods are initialised.
 
* You should always null-check APIs you consume. <tt>GetApi</tt> will return <tt>null</tt> if the API isn't available (e.g. because the mod isn't already installed or doesn't have one), or if an error occurs fetching the API.
 
* You should always null-check APIs you consume. <tt>GetApi</tt> will return <tt>null</tt> if the API isn't available (e.g. because the mod isn't already installed or doesn't have one), or if an error occurs fetching the API.
 +
 +
===Known limitations===
 +
* When providing an API, the interface and implementation must be public.
 +
* When mapping an API to a custom interface using <tt>GetApi&lt;T&gt;</tt> (i.e. not using the mod's original interface), only the API interface itself can be proxied. Method return values and parameters must be types that both mods have access to (e.g. built-in types like <tt>bool</tt>, SMAPI types like <tt>IManifest</tt>, or game types like <tt>GameLocation</tt>).
translators
8,403

edits

Navigation menu