Client LuaCsForBarotrauma
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. More...
 
bool TryGetSubTypesFromACL< T > (Guid id, out IEnumerable< Type > types)
 Tries to get types assignable to type from the ACL given the Guid. More...
 
bool TryGetSubTypesFromACL (Guid id, out IEnumerable< Type > types)
 Tries to get types from the ACL given the Guid. More...
 
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 ". More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

Properties

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

Events

Action< Assembly > OnAssemblyLoaded
 Called when an assembly is loaded. More...
 
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. More...
 
Action< string, Exception > OnException
 Called whenever an exception is thrown. First arg is a formatted message, Second arg is the Exception. More...
 
Action< Guid > OnACLUnload
 For unloading issue debugging. Called whenever MemoryFileAssemblyContextLoader [load context] is unloaded. More...
 
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. More...
 

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.

Definition at line 28 of file AssemblyManager.cs.

Member Function Documentation

◆ FinalizeDispose()

bool AssemblyManager.FinalizeDispose ( )

Definition at line 569 of file AssemblyManager.cs.

◆ GetAllLoadedACLs()

IEnumerable<LoadedACL> 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

Definition at line 335 of file AssemblyManager.cs.

◆ GetAllTypesInLoadedAssemblies()

IEnumerable<Type> 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.

Definition at line 308 of file AssemblyManager.cs.

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

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

Definition at line 100 of file AssemblyManager.cs.

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

IEnumerable<Type> 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.

Definition at line 113 of file AssemblyManager.cs.

◆ GetTypesByName()

IEnumerable<Type> 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.

Definition at line 217 of file AssemblyManager.cs.

◆ LoadAssembliesFromLocations()

AssemblyLoadingSuccessState 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

Definition at line 468 of file AssemblyManager.cs.

◆ LoadAssemblyFromMemory()

AssemblyLoadingSuccessState 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

Definition at line 391 of file AssemblyManager.cs.

◆ SetACLToTemplateMode()

bool 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.

Definition at line 451 of file AssemblyManager.cs.

◆ TryBeginDispose()

bool AssemblyManager.TryBeginDispose ( )

Definition at line 513 of file AssemblyManager.cs.

◆ TryGetACL()

bool 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.

Definition at line 619 of file AssemblyManager.cs.

◆ TryGetSubTypesFromACL()

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

Tries to get types from the ACL given the Guid.

Parameters
id
types
Returns

Definition at line 198 of file AssemblyManager.cs.

◆ TryGetSubTypesFromACL< T >()

bool 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

Definition at line 176 of file AssemblyManager.cs.

Property Documentation

◆ IsCurrentlyUnloading

bool AssemblyManager.IsCurrentlyUnloading
get

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

Definition at line 79 of file AssemblyManager.cs.

◆ StillUnloadingACLs

ImmutableList<WeakReference<MemoryFileAssemblyContextLoader> > AssemblyManager.StillUnloadingACLs
get

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

Definition at line 58 of file AssemblyManager.cs.

Event Documentation

◆ IsReadyToUnloadACL

System.Func<LoadedACL, bool> AssemblyManager.IsReadyToUnloadACL

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

Definition at line 377 of file AssemblyManager.cs.

◆ OnACLUnload

Action<Guid> AssemblyManager.OnACLUnload

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

Definition at line 51 of file AssemblyManager.cs.

◆ OnAssemblyLoaded

Action<Assembly> AssemblyManager.OnAssemblyLoaded

Called when an assembly is loaded.

Definition at line 35 of file AssemblyManager.cs.

◆ OnAssemblyUnloading

Action<Assembly> 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.

Definition at line 41 of file AssemblyManager.cs.

◆ OnException

Action<string, Exception> AssemblyManager.OnException

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

Definition at line 46 of file AssemblyManager.cs.