View Source
  Class TypeExtensions
  
  
  
  
    Inheritance
      System.Object
      
   
  
  Assembly: Umbraco.Core.dll
  Syntax
  
    public static class TypeExtensions
   
  Methods
  
  
    View Source
  
  AllMethods(Type)
  
  
  Declaration
  
    public static IEnumerable<MethodInfo> AllMethods(this Type target)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | target |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Collections.IEnumerable<System.Reflection.MethodInfo> |  | 
    
  
  
    View Source
  
  FirstAttribute<TAttribute>(PropertyInfo)
  
  
  Declaration
  
    public static TAttribute FirstAttribute<TAttribute>(this PropertyInfo propertyInfo)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Reflection.PropertyInfo | propertyInfo |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | TAttribute |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TAttribute |  | 
    
  
  
    View Source
  
  FirstAttribute<TAttribute>(PropertyInfo, Boolean)
  
  
  Declaration
  
    public static TAttribute FirstAttribute<TAttribute>(this PropertyInfo propertyInfo, bool inherit)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Reflection.PropertyInfo | propertyInfo |  | 
      
        | System.Boolean | inherit |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | TAttribute |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TAttribute |  | 
    
  
  
    View Source
  
  FirstAttribute<TAttribute>(Type)
  
  
  Declaration
  
    public static TAttribute FirstAttribute<TAttribute>(this Type type)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | TAttribute |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TAttribute |  | 
    
  
  
    View Source
  
  FirstAttribute<TAttribute>(Type, Boolean)
  
  
  Declaration
  
    public static TAttribute FirstAttribute<TAttribute>(this Type type, bool inherit)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
      
        | System.Boolean | inherit |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | TAttribute |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TAttribute |  | 
    
  
  
    View Source
  
  GetAllMethods(Type)
  Returns all methods including inherited methods even for interfaces
Declaration
  
    public static MethodInfo[] GetAllMethods(this Type type)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Reflection.MethodInfo[] |  | 
    
  
  
  
  
    View Source
  
  GetAllProperties(Type)
  Gets all properties in a flat hierarchy
Declaration
  
    public static PropertyInfo[] GetAllProperties(this Type type)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Reflection.PropertyInfo[] |  | 
    
  
  
  
  
    View Source
  
  GetBaseTypes(Nullable<Type>, Boolean)
  
  
  Declaration
  
    public static IEnumerable<Type?> GetBaseTypes(this Type? type, bool andSelf)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Nullable<Type> | type |  | 
      
        | System.Boolean | andSelf |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Collections.IEnumerable<System.Nullable<Type>> |  | 
    
  
  
    View Source
  
  GetCustomAttribute<T>(Type, Boolean)
  
  
  Declaration
  
    public static T GetCustomAttribute<T>(this Type type, bool inherit)
    where T : Attribute
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
      
        | System.Boolean | inherit |  | 
    
  
  Returns
  
  Type Parameters
  
  
    View Source
  
  GetCustomAttributes<T>(Nullable<Type>, Boolean)
  
  
  Declaration
  
    public static IEnumerable<T> GetCustomAttributes<T>(this Type? type, bool inherited)
    where T : Attribute
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Nullable<Type> | type |  | 
      
        | System.Boolean | inherited |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Collections.IEnumerable<T> |  | 
    
  
  Type Parameters
  
  
    View Source
  
  GetDefaultValue(Type)
  
  
  Declaration
  
    public static object GetDefaultValue(this Type t)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | t |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Object |  | 
    
  
  
    View Source
  
  GetEnumeratedType(Type)
  If the given type is an array or some other collection
comprised of 0 or more instances of a "subtype", get that type
Declaration
  
    public static Type? GetEnumeratedType(this Type type)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type | the source type | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Nullable<Type> |  | 
    
  
  
    View Source
  
  GetFullNameWithAssembly(Type)
  Returns the full type name with the assembly but without all of the assembly specific version information.
Declaration
  
    public static string GetFullNameWithAssembly(this Type type)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.String |  | 
    
  
  
  
  Examples
  The output of this class would be:
Umbraco.Core.TypeExtensions, Umbraco.Core
  
    View Source
  
  GetPublicMethods(Type)
  Returns public methods including inherited methods even for interfaces
Declaration
  
    public static MethodInfo[] GetPublicMethods(this Type type)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Reflection.MethodInfo[] |  | 
    
  
  
    View Source
  
  GetPublicProperties(Type)
  Returns public properties including inherited properties even for interfaces
Declaration
  
    public static PropertyInfo[] GetPublicProperties(this Type type)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Reflection.PropertyInfo[] |  | 
    
  
  
    View Source
  
  HasCustomAttribute<T>(Type, Boolean)
  
  
  Declaration
  
    public static bool HasCustomAttribute<T>(this Type type, bool inherit)
    where T : Attribute
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
      
        | System.Boolean | inherit |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean |  | 
    
  
  Type Parameters
  
  
    View Source
  
  Implements<TInterface>(Type)
  
  
  Declaration
  
    public static bool Implements<TInterface>(this Type type)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TInterface |  | 
    
  
  
    View Source
  
  Inherits(Type, Type)
  
  
  Declaration
  
    public static bool Inherits(this Type type, Type tbase)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
      
        | Type | tbase |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean |  | 
    
  
  
    View Source
  
  Inherits<TBase>(Type)
  
  
  Declaration
  
    public static bool Inherits<TBase>(this Type type)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean |  | 
    
  
  Type Parameters
  
  
    View Source
  
  IsAnonymousType(Type)
  Checks if the type is an anonymous type
Declaration
  
    public static bool IsAnonymousType(this Type type)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean |  | 
    
  
  
  
  
    View Source
  
  IsAssignableFromGtd(Type, Type)
  Determines whether an instance of a specified type can be assigned to the current type instance.
Declaration
  
    public static bool IsAssignableFromGtd(this Type type, Type c)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type | The current type. | 
      
        | Type | c | The type to compare with the current type. | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean | A value indicating whether an instance of the specified type can be assigned to the current type instance. | 
    
  
  
  
  
    View Source
  
  IsEnumerable(Type)
  
  
  Declaration
  
    public static bool IsEnumerable(this Type type)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean | trueif the specified type is enumerable; otherwise,false.
 | 
    
  
  
    View Source
  
  IsOfGenericType(Type, Type)
  Determines whether [is of generic type] [the specified type].
Declaration
  
    public static bool IsOfGenericType(this Type type, Type genericType)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type | The type. | 
      
        | Type | genericType | Type of the generic. | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean | trueif [is of generic type] [the specified type]; otherwise,false.
 | 
    
  
  
    View Source
  
  IsType<T>(Type)
  Determines whether the specified actual type is type.
Declaration
  
    public static bool IsType<T>(this Type actualType)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | actualType | The actual type. | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean | trueif the specified actual type is type; otherwise,false.
 | 
    
  
  Type Parameters
  
  
    View Source
  
  MultipleAttribute<TAttribute>(PropertyInfo)
  
  
  Declaration
  
    public static IEnumerable<TAttribute>? MultipleAttribute<TAttribute>(this PropertyInfo propertyInfo)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Reflection.PropertyInfo | propertyInfo |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Nullable<System.Collections.IEnumerable<TAttribute>> |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TAttribute |  | 
    
  
  
    View Source
  
  MultipleAttribute<TAttribute>(PropertyInfo, Boolean)
  
  
  Declaration
  
    public static IEnumerable<TAttribute>? MultipleAttribute<TAttribute>(this PropertyInfo propertyInfo, bool inherit)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | System.Reflection.PropertyInfo | propertyInfo |  | 
      
        | System.Boolean | inherit |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Nullable<System.Collections.IEnumerable<TAttribute>> |  | 
    
  
  Type Parameters
  
    
      
        | Name | Description | 
    
    
      
        | TAttribute |  | 
    
  
  
    View Source
  
  TryGetGenericArguments(Type, Type, out Type[])
  Will find the generic type of the 'type' parameter passed in that is equal to the 'genericType' parameter passed in
Declaration
  
    public static bool TryGetGenericArguments(this Type type, Type genericType, out Type[] genericArgType)
   
  Parameters
  
    
      
        | Type | Name | Description | 
    
    
      
        | Type | type |  | 
      
        | Type | genericType |  | 
      
        | Type[] | genericArgType |  | 
    
  
  Returns
  
    
      
        | Type | Description | 
    
    
      
        | System.Boolean |  |