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#
Inheritance
System.Object
Assembly: Umbraco.Core.dll
Syntax
public static class TypeHelper
Methods
View Source
CachedDiscoverableFields(Type)
Gets (and caches) System.Reflection.FieldInfo discoverable in the current for a given
type
.
Declaration
public static FieldInfo[] CachedDiscoverableFields(Type type)
Parameters
Type |
Name |
Description |
Type |
type |
The source.
|
Returns
Type |
Description |
System.Reflection.FieldInfo[] |
|
View Source
CachedDiscoverableProperties(Type, Boolean, Boolean, Boolean)
Gets (and caches) System.Reflection.PropertyInfo discoverable in the current 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.
|
System.Boolean |
mustRead |
true if the properties discovered are readable
|
System.Boolean |
mustWrite |
true if the properties discovered are writable
|
System.Boolean |
includeIndexed |
true if the properties discovered are indexable
|
Returns
Type |
Description |
System.Reflection.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 |
System.Object |
obj |
|
Returns
Type |
Description |
System.Collections.IList |
|
View Source
GetLowestBaseType(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
Type |
Description |
Attempt<System.Nullable<Type>> |
|
View Source
GetProperty(Type, String, Boolean, Boolean, Boolean, Boolean)
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 |
|
System.String |
name |
|
System.Boolean |
mustRead |
|
System.Boolean |
mustWrite |
|
System.Boolean |
includeIndexed |
|
System.Boolean |
caseSensitive |
|
Returns
Type |
Description |
System.Reflection.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 |
System.Reflection.Assembly |
assembly |
The referenced assembly.
|
System.Collections.IEnumerable<System.Reflection.Assembly> |
assemblies |
A list of assemblies.
|
Returns
Type |
Description |
IReadOnlyList<System.Reflection.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 |
System.Reflection.Assembly |
assembly |
|
System.String |
name |
|
Returns
Type |
Description |
System.Boolean |
|
View Source
IsImplicitValueType(Type)
A method to determine whether implementation
is an implied value type (
, or a string).
Declaration
public static bool IsImplicitValueType(Type implementation)
Parameters
Type |
Name |
Description |
Type |
implementation |
The implementation.
|
Returns
Type |
Description |
System.Boolean |
|
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
Type |
Description |
System.Boolean |
|
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 |
System.Reflection.MethodInfo |
m |
|
Returns
Type |
Description |
System.Boolean |
|
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
Type |
Description |
System.Boolean |
|
View Source
IsTypeAssignableFrom(Type, Nullable<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.
|
System.Nullable<Type> |
implementation |
The implementation.
|
Returns
Type |
Description |
System.Boolean |
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 |
System.Object |
implementation |
The implementation.
|
Returns
Type |
Description |
System.Boolean |
|
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 |
Description |
System.Boolean |
|
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
Type |
Description |
System.Boolean |
|
View Source
MatchType(Type, Type)
Declaration
public static bool MatchType(Type implementation, Type contract)
Parameters
Type |
Name |
Description |
Type |
implementation |
|
Type |
contract |
|
Returns
Type |
Description |
System.Boolean |
|
View Source
MatchType(Type, Type, IDictionary<String, Type>, Boolean)
Declaration
public static bool MatchType(Type implementation, Type contract, IDictionary<string, Type> bindings, bool variance = true)
Parameters
Type |
Name |
Description |
Type |
implementation |
|
Type |
contract |
|
System.Collections.IDictionary<System.String, Type> |
bindings |
|
System.Boolean |
variance |
|
Returns
Type |
Description |
System.Boolean |
|