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.Core.dll
Syntax
public static class TypeLoader

Fields

CecilResolver

Default assembly resolved used by the TypeLoader

Declaration
public static readonly DefaultAssemblyResolver CecilResolver
Field Value
Type Description
DefaultAssemblyResolver

ReaderParameters

Default reader parameters used by TypeLoader

Declaration
public static readonly ReaderParameters ReaderParameters
Field Value
Type Description
ReaderParameters

SearchDirectories

Declaration
public static HashSet<string> SearchDirectories
Field Value
Type Description
System.Collections.Generic.HashSet<System.String>

Methods

CecilResolveOnFailure(Object, AssemblyNameReference)

Declaration
public static AssemblyDefinition CecilResolveOnFailure(object sender, AssemblyNameReference reference)
Parameters
Type Name Description
System.Object sender
AssemblyNameReference reference
Returns
Type Description
AssemblyDefinition

FindPluginTypes<T>(String, Func<TypeDefinition, String, 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, string, 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, System.String, 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>>, Dictionary<String, String>)

Saves indexed type metadata into a cache.

Declaration
public static void SaveAssemblyCache<T>(string cacheName, Dictionary<string, List<T>> entries, Dictionary<string, string> hashes)
    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

System.Collections.Generic.Dictionary<System.String, System.String> hashes

Hash values that can be used for checking similarity between cached and live assembly

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