Class TypeLoader
Provides methods to find and instantiate types.
Inheritance
Namespace: Umbraco.Cms.Core.Composing
Assembly: Umbraco.Core.dll
Syntax
public sealed class TypeLoader
Remarks
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 |
TypeLoader(ITypeFinder, IRuntimeHash, IAppPolicyCache, DirectoryInfo, ILogger<TypeLoader>, IProfiler, Boolean, Nullable<IEnumerable<Assembly>>)
Initializes a new instance of the TypeLoader class.
Declaration
public TypeLoader(ITypeFinder typeFinder, IRuntimeHash runtimeHash, IAppPolicyCache runtimeCache, DirectoryInfo localTempPath, ILogger<TypeLoader> logger, IProfiler profiler, bool detectChanges, IEnumerable<Assembly>? assembliesToScan = null)
Parameters
Type | Name | Description |
---|---|---|
ITypeFinder | typeFinder | |
IRuntimeHash | runtimeHash | |
IAppPolicyCache | runtimeCache | |
DirectoryInfo | localTempPath | |
ILogger<TypeLoader> | logger | |
IProfiler | profiler | |
System.Boolean | detectChanges | |
System.Nullable<IEnumerable<System.Reflection.Assembly>> | assembliesToScan |
TypeLoader(ITypeFinder, IRuntimeHash, IAppPolicyCache, DirectoryInfo, ILogger<TypeLoader>, IProfiler, Nullable<IEnumerable<Assembly>>)
Initializes a new instance of the TypeLoader class.
Declaration
public TypeLoader(ITypeFinder typeFinder, IRuntimeHash runtimeHash, IAppPolicyCache runtimeCache, DirectoryInfo localTempPath, ILogger<TypeLoader> logger, IProfiler profiler, IEnumerable<Assembly>? assembliesToScan = null)
Parameters
Type | Name | Description |
---|---|---|
ITypeFinder | typeFinder | |
IRuntimeHash | runtimeHash | |
IAppPolicyCache | runtimeCache | |
DirectoryInfo | localTempPath | |
ILogger<TypeLoader> | logger | |
IProfiler | profiler | |
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 SourceAddTypeList(TypeLoader.TypeList)
Sets a type list.
Declaration
public void AddTypeList(TypeLoader.TypeList typeList)
Parameters
Type | Name | Description |
---|---|---|
TypeLoader.TypeList | typeList |
Remarks
For unit tests.
ClearTypesCache()
Clears cache.
Declaration
public void ClearTypesCache()
Remarks
Generally only used for resetting cache, for example during the install process.
GetAssemblyAttributes(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 : Attribute
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 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.
GetTypesListFilePath()
Declaration
public string GetTypesListFilePath()
Returns
Type | Description |
---|---|
System.String |
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 : Attribute
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 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.
ReadCache()
Declaration
public Dictionary<(string, string), IEnumerable<string>>? ReadCache()
Returns
Type | Description |
---|---|
System.Nullable<Umbraco.Cms.Core.Dictionary<System.ValueTuple<System.String, System.String>, IEnumerable<System.String>>> |
TryGetCached(Type, Type)
Declaration
public Attempt<IEnumerable<string>> TryGetCached(Type baseType, Type attributeType)
Parameters
Type | Name | Description |
---|---|---|
Type | baseType | |
Type | attributeType |
Returns
Type | Description |
---|---|
Attempt<IEnumerable<System.String>> |
WriteCache()
Declaration
public void WriteCache()