Class TypeLoader

Provides methods for loading specified types from an assembly.

Inheritance
System.Object TypeLoader
Inherited Members
System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace: BepInEx.Bootstrap
Assembly: BepInEx.dll
Syntax
public static class TypeLoader

Fields

ReaderParameters

Default reader parameters used by TypeLoader

Declaration
public static readonly ReaderParameters ReaderParameters
Field Value
Type Description
ReaderParameters

Resolver

Default assembly resolved used by the TypeLoader

Declaration
public static readonly DefaultAssemblyResolver Resolver
Field Value
Type Description
DefaultAssemblyResolver

Methods

FindPluginTypes<T>(String, Func<TypeDefinition, T>, Func<AssemblyDefinition, Boolean>, String)

Looks up assemblies in the given directory and locates all types that can be loaded and collects their metadata.

Declaration
public static Dictionary<string, List<T>> FindPluginTypes<T>(string directory, Func<TypeDefinition, T> typeSelector, Func<AssemblyDefinition, bool> assemblyFilter = null, string cacheName = null)
    where T : ICacheable, new()
Parameters
Type Name Description
System.String directory

The directory to search for assemblies.

System.Func<TypeDefinition, T> typeSelector

A function to check if a type should be selected and to build the type metadata.

System.Func<AssemblyDefinition, System.Boolean> assemblyFilter

A filter function to quickly determine if the assembly can be loaded.

System.String cacheName

The name of the cache to get cached types from.

Returns
Type Description
System.Collections.Generic.Dictionary<System.String, System.Collections.Generic.List<T>>

A dictionary of all assemblies in the directory and the list of type metadatas of types that match the selector.

Type Parameters
Name Description
T

The specific base type to search for.

LoadAssemblyCache<T>(String)

Loads an index of type metadatas from a cache.

Declaration
public static Dictionary<string, CachedAssembly<T>> LoadAssemblyCache<T>(string cacheName)
    where T : ICacheable, new()
Parameters
Type Name Description
System.String cacheName

Name of the cache

Returns
Type Description
System.Collections.Generic.Dictionary<System.String, CachedAssembly<T>>

Cached type metadatas indexed by the path of the assembly that defines the type. If no cache is defined, return null.

Type Parameters
Name Description
T

Cacheable item

SaveAssemblyCache<T>(String, Dictionary<String, List<T>>)

Saves indexed type metadata into a cache.

Declaration
public static void SaveAssemblyCache<T>(string cacheName, Dictionary<string, List<T>> entries)
    where T : ICacheable
Parameters
Type Name Description
System.String cacheName

Name of the cache

System.Collections.Generic.Dictionary<System.String, System.Collections.Generic.List<T>> entries

List of plugin metadatas indexed by the path to the assembly that contains the types

Type Parameters
Name Description
T

Cacheable item

TypeLoadExceptionToString(ReflectionTypeLoadException)

Converts TypeLoadException to a readable string.

Declaration
public static string TypeLoadExceptionToString(ReflectionTypeLoadException ex)
Parameters
Type Name Description
System.Reflection.ReflectionTypeLoadException ex

TypeLoadException

Returns
Type Description
System.String

Readable representation of the exception

Events

AssemblyResolve

Event fired when TypeLoader fails to resolve a type during type loading.

Declaration
public static event AssemblyResolveEventHandler AssemblyResolve
Event Type
Type Description
AssemblyResolveEventHandler