Search Results for

    Show / Hide Table of Contents
    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
    Namespace: Umbraco.Cms.Core.Composing
    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>>
    Remarks

    The term 'lowest' refers to the most base class of the type collection. If a base type is not found amongst the type collection then an invalid attempt is returned.

    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>
    Remarks

    If the assembly of the assignTypeFrom Type is in the App_Code assembly, then we return nothing since things cannot reference that assembly, same with the global.asax 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
    Remarks

    In IL a static class is abstract and sealed see: http://stackoverflow.com/questions/1175888/determine-if-a-type-is-static

    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
    • Improve this Doc
    • View Source
    In This Article
    • Methods
      • CachedDiscoverableFields(Type)
      • CachedDiscoverableProperties(Type, Boolean, Boolean, Boolean)
      • CreateGenericEnumerableFromObject(Object)
      • GetLowestBaseType(Type[])
      • GetProperty(Type, String, Boolean, Boolean, Boolean, Boolean)
      • GetReferencingAssemblies(Assembly, IEnumerable<Assembly>)
      • HasReference(Assembly, String)
      • IsImplicitValueType(Type)
      • IsNonStaticClass(Type)
      • IsOverride(MethodInfo)
      • IsStaticClass(Type)
      • IsTypeAssignableFrom(Type, Nullable<Type>)
      • IsTypeAssignableFrom<TContract>(Object)
      • IsTypeAssignableFrom<TContract>(Type)
      • IsValueType(Type)
      • MatchType(Type, Type)
      • MatchType(Type, Type, IDictionary<String, Type>, Boolean)
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX