Class TypeLoader
Provides methods to find and instantiate types.
Inheritance
Namespace: Umbraco.Cms.Core.Composing
Assembly: Umbraco.Core.dll
Syntax
public sealed class TypeLoaderRemarks
This class should be used to get all types, the ITypeFinder class should never be used directly.
In most cases this class is not used directly but through extension methods that retrieve specific types.
Constructors
View SourceTypeLoader(ITypeFinder, ILogger<TypeLoader>, Nullable<IEnumerable<Assembly>>)
Declaration
public TypeLoader(ITypeFinder typeFinder, ILogger<TypeLoader> logger, IEnumerable<Assembly>? assembliesToScan = null)Parameters
| Type | Name | Description | 
|---|---|---|
| ITypeFinder | typeFinder | |
| ILogger<TypeLoader> | logger | |
| System.Nullable<IEnumerable<System.Reflection.Assembly>> | assembliesToScan | 
Properties
View SourceAssembliesToScan
Gets or sets the set of assemblies to scan.
Declaration
public IEnumerable<Assembly> AssembliesToScan { get; }Property Value
| Type | Description | 
|---|---|
| IEnumerable<System.Reflection.Assembly> | 
Remarks
If not explicitly set, defaults to all assemblies except those that are know to not have any of the types we might scan. Because we only scan for application types, this means we can safely exclude GAC assemblies for example.
This is for unit tests.
TypeFinder
Returns the underlying ITypeFinder
Declaration
public ITypeFinder TypeFinder { get; }Property Value
| Type | Description | 
|---|---|
| ITypeFinder | 
TypeLists
Gets the type lists.
Declaration
public IEnumerable<TypeLoader.TypeList> TypeLists { get; }Property Value
| Type | Description | 
|---|---|
| IEnumerable<TypeLoader.TypeList> | 
Remarks
For unit tests.
Methods
View SourceGetAssemblyAttributes(Type[])
Gets the assembly attributes of the specified attributeTypes.
Declaration
public IEnumerable<Attribute> GetAssemblyAttributes(params Type[] attributeTypes)Parameters
| Type | Name | Description | 
|---|---|---|
| Type[] | attributeTypes | The attribute types. | 
Returns
| Type | Description | 
|---|---|
| IEnumerable<Attribute> | The assembly attributes of the specified types. | 
GetAttributedTypes<TAttribute>(Boolean, Nullable<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 : AttributeParameters
| Type | Name | Description | 
|---|---|---|
| System.Boolean | cache | Indicates whether to use cache for type resolution. | 
| System.Nullable<IEnumerable<System.Reflection.Assembly>> | specificAssemblies | A set of assemblies for type resolution. | 
Returns
| Type | Description | 
|---|---|
| IEnumerable<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, Nullable<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.Nullable<IEnumerable<System.Reflection.Assembly>> | specificAssemblies | A set of assemblies for type resolution. | 
Returns
| Type | Description | 
|---|---|
| IEnumerable<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, Nullable<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 : AttributeParameters
| Type | Name | Description | 
|---|---|---|
| System.Boolean | cache | Indicates whether to use cache for type resolution. | 
| System.Nullable<IEnumerable<System.Reflection.Assembly>> | specificAssemblies | A set of assemblies for type resolution. | 
Returns
| Type | Description | 
|---|---|
| IEnumerable<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.