Barotrauma Client
Loading...
Searching...
No Matches
Barotrauma.AssemblyManager Class Reference

Provides functionality for the loading, unloading and management of plugins implementing IAssemblyPlugin. All plugins are loaded into their own AssemblyLoadContext along with their dependencies. More...

Classes

class  LoadedACL
 

Public Member Functions

IEnumerable< Type > GetSubTypesInLoadedAssemblies< T > ()
 
IEnumerable< Type > GetSubTypesInLoadedAssemblies< T > (bool rebuildList)
 Allows iteration over all non-interface types in all loaded assemblies in the AsmMgr that are assignable to the given type (IsAssignableFrom). Warning: care should be used when using this method in hot paths as performance may be affected.
 
bool TryGetSubTypesFromACL< T > (Guid id, out IEnumerable< Type > types)
 Tries to get types assignable to type from the ACL given the Guid.
 
bool TryGetSubTypesFromACL (Guid id, out IEnumerable< Type > types)
 Tries to get types from the ACL given the Guid.
 
IEnumerable< Type > GetTypesByName (string typeName)
 Allows iteration over all types, including interfaces, in all loaded assemblies in the AsmMgr who's names match the string. Note: Will return the by-reference equivalent type if the type name is prefixed with "out " or "ref ".
 
IEnumerable< Type > GetAllTypesInLoadedAssemblies ()
 Allows iteration over all types (including interfaces) in all loaded assemblies managed by the AsmMgr. Warning: High usage may result in performance issues.
 
IEnumerable< LoadedACLGetAllLoadedACLs ()
 Returns a list of all loaded ACLs. WARNING: References to these ACLs outside of the AssemblyManager should be kept in a WeakReference in order to avoid causing issues with unloading/disposal.
 
AssemblyLoadingSuccessState LoadAssemblyFromMemory ([NotNull] string compiledAssemblyName, [NotNull] IEnumerable< SyntaxTree > syntaxTree, IEnumerable< MetadataReference > externalMetadataReferences, [NotNull] CSharpCompilationOptions compilationOptions, string friendlyName, ref Guid id, IEnumerable< Assembly > externFileAssemblyRefs=null)
 Compiles an assembly from supplied references and syntax trees into the specified AssemblyContextLoader. A new ACL will be created if the Guid supplied is Guid.Empty.
 
bool SetACLToTemplateMode (Guid guid)
 Switches the ACL with the given Guid to Template Mode, which disables assembly name resolution for any assemblies loaded in it. These ACLs are intended to be used to host Assemblies for information only and not for code execution. WARNING: This process is irreversible.
 
AssemblyLoadingSuccessState LoadAssembliesFromLocations ([NotNull] IEnumerable< string > filePaths, string friendlyName, ref Guid id)
 Tries to load all assemblies at the supplied file paths list into the ACl with the given Guid. If the supplied Guid is Empty, then a new ACl will be created and the Guid will be assigned to it.
 
bool TryBeginDispose ()
 
bool FinalizeDispose ()
 
bool TryGetACL (Guid id, out LoadedACL acl)
 Tries to retrieve the LoadedACL with the given ID or null if none is found. WARNING: External references to this ACL with long lifespans should be kept in a WeakReference to avoid causing unloading/disposal issues.
 

Properties

ImmutableList< WeakReference< MemoryFileAssemblyContextLoader > > StillUnloadingACLs [get]
 [DEBUG ONLY] Returns a list of the current unloading ACLs.
 
bool IsCurrentlyUnloading [get]
 Checks if there are any AssemblyLoadContexts still in the process of unloading.
 

Events

Action< Assembly > OnAssemblyLoaded
 Called when an assembly is loaded.
 
Action< Assembly > OnAssemblyUnloading
 Called when an assembly is marked for unloading, before unloading begins. You should use this to cleanup any references that you have to this assembly.
 
Action< string, Exception > OnException
 Called whenever an exception is thrown. First arg is a formatted message, Second arg is the Exception.
 
Action< Guid > OnACLUnload
 For unloading issue debugging. Called whenever MemoryFileAssemblyContextLoader [load context] is unloaded.
 
System.Func< LoadedACL, bool > IsReadyToUnloadACL
 Used by content package and plugin management to stop unloading of a given ACL until all plugins have gracefully closed.
 

Detailed Description

Provides functionality for the loading, unloading and management of plugins implementing IAssemblyPlugin. All plugins are loaded into their own AssemblyLoadContext along with their dependencies.

Member Function Documentation

◆ FinalizeDispose()

bool Barotrauma.AssemblyManager.FinalizeDispose ( )

◆ GetAllLoadedACLs()

IEnumerable< LoadedACL > Barotrauma.AssemblyManager.GetAllLoadedACLs ( )

Returns a list of all loaded ACLs. WARNING: References to these ACLs outside of the AssemblyManager should be kept in a WeakReference in order to avoid causing issues with unloading/disposal.

Returns

◆ GetAllTypesInLoadedAssemblies()

IEnumerable< Type > Barotrauma.AssemblyManager.GetAllTypesInLoadedAssemblies ( )

Allows iteration over all types (including interfaces) in all loaded assemblies managed by the AsmMgr. Warning: High usage may result in performance issues.

Returns
An Enumerator for iteration.

◆ GetSubTypesInLoadedAssemblies< T >() [1/2]

IEnumerable< Type > Barotrauma.AssemblyManager.GetSubTypesInLoadedAssemblies< T > ( )

◆ GetSubTypesInLoadedAssemblies< T >() [2/2]

IEnumerable< Type > Barotrauma.AssemblyManager.GetSubTypesInLoadedAssemblies< T > ( bool rebuildList)

Allows iteration over all non-interface types in all loaded assemblies in the AsmMgr that are assignable to the given type (IsAssignableFrom). Warning: care should be used when using this method in hot paths as performance may be affected.

Template Parameters
TThe type to compare against
Parameters
rebuildListForces caches to clear and for the lists of types to be rebuilt.
Returns
An Enumerator for matching types.

◆ GetTypesByName()

IEnumerable< Type > Barotrauma.AssemblyManager.GetTypesByName ( string typeName)

Allows iteration over all types, including interfaces, in all loaded assemblies in the AsmMgr who's names match the string. Note: Will return the by-reference equivalent type if the type name is prefixed with "out " or "ref ".

Parameters
typeNameThe string name of the type to search for.
Returns
An Enumerator for matching types. List will be empty if bad params are supplied.

◆ LoadAssembliesFromLocations()

AssemblyLoadingSuccessState Barotrauma.AssemblyManager.LoadAssembliesFromLocations ( [NotNull] IEnumerable< string > filePaths,
string friendlyName,
ref Guid id )

Tries to load all assemblies at the supplied file paths list into the ACl with the given Guid. If the supplied Guid is Empty, then a new ACl will be created and the Guid will be assigned to it.

Parameters
filePathsList of assemblies to try and load.
friendlyNameA non-unique name for later reference. Optional.
idGuid of the ACL or Empty if none specified. Guid of ACL will be assigned to this var.
Returns
Operation success messages.
Exceptions
ArgumentNullException

◆ LoadAssemblyFromMemory()

AssemblyLoadingSuccessState Barotrauma.AssemblyManager.LoadAssemblyFromMemory ( [NotNull] string compiledAssemblyName,
[NotNull] IEnumerable< SyntaxTree > syntaxTree,
IEnumerable< MetadataReference > externalMetadataReferences,
[NotNull] CSharpCompilationOptions compilationOptions,
string friendlyName,
ref Guid id,
IEnumerable< Assembly > externFileAssemblyRefs = null )

Compiles an assembly from supplied references and syntax trees into the specified AssemblyContextLoader. A new ACL will be created if the Guid supplied is Guid.Empty.

Parameters
compiledAssemblyName
syntaxTree
externalMetadataReferences
compilationOptions
friendlyNameA non-unique name for later reference. Optional, set to null if unused.
idThe guid of the assembly
externFileAssemblyRefs
Returns

◆ SetACLToTemplateMode()

bool Barotrauma.AssemblyManager.SetACLToTemplateMode ( Guid guid)

Switches the ACL with the given Guid to Template Mode, which disables assembly name resolution for any assemblies loaded in it. These ACLs are intended to be used to host Assemblies for information only and not for code execution. WARNING: This process is irreversible.

Parameters
guidGuid of the ACL.
Returns
Whether or not an ACL was found with the given ID.

◆ TryBeginDispose()

bool Barotrauma.AssemblyManager.TryBeginDispose ( )

◆ TryGetACL()

bool Barotrauma.AssemblyManager.TryGetACL ( Guid id,
out LoadedACL acl )

Tries to retrieve the LoadedACL with the given ID or null if none is found. WARNING: External references to this ACL with long lifespans should be kept in a WeakReference to avoid causing unloading/disposal issues.

Parameters
idGUID of the ACL.
aclThe found ACL or null if none was found.
Returns
Whether or not an ACL was found.

◆ TryGetSubTypesFromACL()

bool Barotrauma.AssemblyManager.TryGetSubTypesFromACL ( Guid id,
out IEnumerable< Type > types )

Tries to get types from the ACL given the Guid.

Parameters
id
types
Returns

◆ TryGetSubTypesFromACL< T >()

bool Barotrauma.AssemblyManager.TryGetSubTypesFromACL< T > ( Guid id,
out IEnumerable< Type > types )

Tries to get types assignable to type from the ACL given the Guid.

Parameters
id
types
Template Parameters
T
Returns

Property Documentation

◆ IsCurrentlyUnloading

bool Barotrauma.AssemblyManager.IsCurrentlyUnloading
get

Checks if there are any AssemblyLoadContexts still in the process of unloading.

◆ StillUnloadingACLs

ImmutableList<WeakReference<MemoryFileAssemblyContextLoader> > Barotrauma.AssemblyManager.StillUnloadingACLs
get

[DEBUG ONLY] Returns a list of the current unloading ACLs.

Event Documentation

◆ IsReadyToUnloadACL

System.Func<LoadedACL, bool> Barotrauma.AssemblyManager.IsReadyToUnloadACL

Used by content package and plugin management to stop unloading of a given ACL until all plugins have gracefully closed.

◆ OnACLUnload

Action<Guid> Barotrauma.AssemblyManager.OnACLUnload

For unloading issue debugging. Called whenever MemoryFileAssemblyContextLoader [load context] is unloaded.

◆ OnAssemblyLoaded

Action<Assembly> Barotrauma.AssemblyManager.OnAssemblyLoaded

Called when an assembly is loaded.

◆ OnAssemblyUnloading

Action<Assembly> Barotrauma.AssemblyManager.OnAssemblyUnloading

Called when an assembly is marked for unloading, before unloading begins. You should use this to cleanup any references that you have to this assembly.

◆ OnException

Action<string, Exception> Barotrauma.AssemblyManager.OnException

Called whenever an exception is thrown. First arg is a formatted message, Second arg is the Exception.


The documentation for this class was generated from the following file: