Class TypeLoader
Provides methods to find and instantiate types.
Inheritance
Namespace: Umbraco.Core.Composing
Assembly: Umbraco.Core.dll
Syntax
public class TypeLoader
Remarks
This class should be used to get all types, the TypeFinder class should never be used directly.
In most cases this class is not used directly but through extension methods that retrieve specific types.
This class caches the types it knows to avoid excessive assembly scanning and shorten startup times, relying on a hash of the DLLs in the ~/bin folder to check for cache expiration.
Constructors
View SourceTypeLoader(IAppPolicyCache, String, IProfilingLogger)
Initializes a new instance of the TypeLoader class.
Declaration
public TypeLoader(IAppPolicyCache runtimeCache, string localTempPath, IProfilingLogger logger)
Parameters
Type | Name | Description |
---|---|---|
IAppPolicyCache | runtimeCache | The application runtime cache. |
System.String | localTempPath | Files storage location. |
IProfilingLogger | logger | A profiling logger. |
Methods
View SourceClearTypesCache()
Removes cache files and internal cache.
Declaration
public void ClearTypesCache()
Remarks
Generally only used for resetting cache, for example during the install process.
GetAssemblyAttributes()
Gets all the assembly attributes.
Declaration
public IEnumerable<Attribute> GetAssemblyAttributes()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Attribute> | All assembly attributes. |
GetAssemblyAttributes(Type[])
Gets the assembly attributes of the specified attributeTypes
.
Declaration
public IEnumerable<Attribute> GetAssemblyAttributes(params Type[] attributeTypes)
Parameters
Type | Name | Description |
---|---|---|
System.Type[] | attributeTypes | The attribute types. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Attribute> | The assembly attributes of the specified types. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | attributeTypes |
GetAssemblyAttributes<T>()
Gets the assembly attributes of the specified type T
.
Declaration
public IEnumerable<T> GetAssemblyAttributes<T>()
where T : Attribute
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> | The assembly attributes of the specified type |
Type Parameters
Name | Description |
---|---|
T | The attribute type. |
GetAttributedTypes<TAttribute>(Boolean, IEnumerable<Assembly>)
Gets class types marked with the specified attribute.
Declaration
public IEnumerable<Type> GetAttributedTypes<TAttribute>(bool cache = true, IEnumerable<Assembly> specificAssemblies = null)
where TAttribute : Attribute
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | cache | Indicates whether to use cache for type resolution. |
System.Collections.Generic.IEnumerable<System.Reflection.Assembly> | specificAssemblies | A set of assemblies for type resolution. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> | All class types marked with the specified attribute. |
Type Parameters
Name | Description |
---|---|
TAttribute | The type of the attribute. |
Remarks
Caching is disabled when using specific assemblies.
GetTypes<T>(Boolean, IEnumerable<Assembly>)
Gets class types inheriting from or implementing the specified type
Declaration
public IEnumerable<Type> GetTypes<T>(bool cache = true, IEnumerable<Assembly> specificAssemblies = null)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | cache | Indicates whether to use cache for type resolution. |
System.Collections.Generic.IEnumerable<System.Reflection.Assembly> | specificAssemblies | A set of assemblies for type resolution. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> | All class types inheriting from or implementing the specified type. |
Type Parameters
Name | Description |
---|---|
T | The type to inherit from or implement. |
Remarks
Caching is disabled when using specific assemblies.
GetTypesWithAttribute<T, TAttribute>(Boolean, IEnumerable<Assembly>)
Gets class types inheriting from or implementing the specified type and marked with the specified attribute.
Declaration
public IEnumerable<Type> GetTypesWithAttribute<T, TAttribute>(bool cache = true, IEnumerable<Assembly> specificAssemblies = null)
where TAttribute : Attribute
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | cache | Indicates whether to use cache for type resolution. |
System.Collections.Generic.IEnumerable<System.Reflection.Assembly> | specificAssemblies | A set of assemblies for type resolution. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> | All class types inheriting from or implementing the specified type and marked with the specified attribute. |
Type Parameters
Name | Description |
---|---|
T | The type to inherit from or implement. |
TAttribute | The type of the attribute. |
Remarks
Caching is disabled when using specific assemblies.