View Source
Class TypeHelper
A utility class for type checking, this provides internal caching so that calls to these methods will be faster
than doing a manual type check in c#
Assembly: Umbraco.Core.dll
Syntax
public static class TypeHelper
Methods
View Source
CachedDiscoverableFields(Type)
Gets (and caches) System.Reflection.FieldInfo discoverable in the current System.AppDomain for a given
type.
Declaration
public static FieldInfo[] CachedDiscoverableFields(Type type)
Parameters
| Type |
Name |
Description |
| Type |
type |
The source.
|
Returns
| Type |
Description |
| FieldInfo[] |
|
View Source
CachedDiscoverableProperties(Type, bool, bool, bool)
Gets (and caches) System.Reflection.PropertyInfo discoverable in the current System.AppDomain for a given
type.
Declaration
public static PropertyInfo[] CachedDiscoverableProperties(Type type, bool mustRead = true, bool mustWrite = true, bool includeIndexed = false)
Parameters
| Type |
Name |
Description |
| Type |
type |
The source.
|
| bool |
mustRead |
true if the properties discovered are readable
|
| bool |
mustWrite |
true if the properties discovered are writable
|
| bool |
includeIndexed |
true if the properties discovered are indexable
|
Returns
| Type |
Description |
| PropertyInfo[] |
|
View Source
CreateGenericEnumerableFromObject(object?)
Based on a type we'll check if it is IEnumerable{T} (or similar) and if so we'll return a List{T}, this will also
deal with array types and return List{T} for those too.
If it cannot be done, null is returned.
Declaration
public static IList? CreateGenericEnumerableFromObject(object? obj)
Parameters
| Type |
Name |
Description |
| object |
obj |
|
Returns
View Source
GetLowestBaseType(params Type[])
Finds a lowest base class amongst a collection of types
Declaration
public static Attempt<Type?> GetLowestBaseType(params Type[] types)
Parameters
| Type |
Name |
Description |
| Type[] |
types |
|
Returns
View Source
GetProperty(Type, string, bool, bool, bool, bool)
Returns (and caches) a PropertyInfo from a type
Declaration
public static PropertyInfo? GetProperty(Type type, string name, bool mustRead = true, bool mustWrite = true, bool includeIndexed = false, bool caseSensitive = true)
Parameters
| Type |
Name |
Description |
| Type |
type |
|
| string |
name |
|
| bool |
mustRead |
|
| bool |
mustWrite |
|
| bool |
includeIndexed |
|
| bool |
caseSensitive |
|
Returns
| Type |
Description |
| PropertyInfo |
|
View Source
GetReferencingAssemblies(Assembly, IEnumerable<Assembly>)
Find all assembly references that are referencing the assignTypeFrom Type's assembly found in the assemblyList
Declaration
public static IReadOnlyList<Assembly> GetReferencingAssemblies(Assembly assembly, IEnumerable<Assembly> assemblies)
Parameters
| Type |
Name |
Description |
| Assembly |
assembly |
The referenced assembly.
|
| IEnumerable<Assembly> |
assemblies |
A list of assemblies.
|
Returns
| Type |
Description |
| IReadOnlyList<Assembly> |
|
View Source
HasReference(Assembly, string)
Determines if an assembly references another assembly.
Declaration
public static bool HasReference(Assembly assembly, string name)
Parameters
| Type |
Name |
Description |
| Assembly |
assembly |
|
| string |
name |
|
Returns
View Source
IsImplicitValueType(Type)
A method to determine whether implementation is an implied value type (
System.Type.IsValueType, System.Type.IsEnum or a string).
Declaration
public static bool IsImplicitValueType(Type implementation)
Parameters
| Type |
Name |
Description |
| Type |
implementation |
The implementation.
|
Returns
View Source
IsNonStaticClass(Type)
Returns true if the type is a class and is not static
Declaration
public static bool IsNonStaticClass(Type t)
Parameters
| Type |
Name |
Description |
| Type |
t |
|
Returns
View Source
IsOverride(MethodInfo)
Checks if the method is actually overriding a base method
Declaration
public static bool IsOverride(MethodInfo m)
Parameters
| Type |
Name |
Description |
| MethodInfo |
m |
|
Returns
View Source
IsStaticClass(Type)
Returns true if the type is a static class
Declaration
public static bool IsStaticClass(Type type)
Parameters
| Type |
Name |
Description |
| Type |
type |
|
Returns
View Source
IsTypeAssignableFrom(Type, Type?)
Determines whether the type implementation is assignable from the specified implementation,
and caches the result across the application using a System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue>.
Declaration
public static bool IsTypeAssignableFrom(Type contract, Type? implementation)
Parameters
| Type |
Name |
Description |
| Type |
contract |
The type of the contract.
|
| Type |
implementation |
The implementation.
|
Returns
| Type |
Description |
| bool |
true if [is type assignable from] [the specified contract]; otherwise, false.
|
View Source
IsTypeAssignableFrom<TContract>(object)
Determines whether the object instance implementation is assignable from the specified
implementation TContract,
and caches the result across the application using a System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue>.
Declaration
public static bool IsTypeAssignableFrom<TContract>(object implementation)
Parameters
| Type |
Name |
Description |
| object |
implementation |
The implementation.
|
Returns
Type Parameters
| Name |
Description |
| TContract |
The type of the contract.
|
View Source
IsTypeAssignableFrom<TContract>(Type)
Determines whether the type implementation is assignable from the specified implementation
TContract,
and caches the result across the application using a System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue>.
Declaration
public static bool IsTypeAssignableFrom<TContract>(Type implementation)
Parameters
| Type |
Name |
Description |
| Type |
implementation |
The implementation.
|
Returns
Type Parameters
| Name |
Description |
| TContract |
The type of the contract.
|
View Source
IsValueType(Type)
A method to determine whether implementation represents a value type.
Declaration
public static bool IsValueType(Type implementation)
Parameters
| Type |
Name |
Description |
| Type |
implementation |
The implementation.
|
Returns
View Source
MatchType(Type, Type)
Declaration
public static bool MatchType(Type implementation, Type contract)
Parameters
| Type |
Name |
Description |
| Type |
implementation |
|
| Type |
contract |
|
Returns
View Source
MatchType(Type, Type, IDictionary<string, Type>, bool)
Declaration
public static bool MatchType(Type implementation, Type contract, IDictionary<string, Type> bindings, bool variance = true)
Parameters
| Type |
Name |
Description |
| Type |
implementation |
|
| Type |
contract |
|
| IDictionary<string, Type> |
bindings |
|
| bool |
variance |
|
Returns