docs.unity3d.com
    Show / Hide Table of Contents

    Class TypeUtility

    Utility class around Type.

    Inheritance
    Object
    TypeUtility
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.Properties
    Syntax
    public static class TypeUtility

    Methods

    CanBeInstantiated(Type)

    Returns true if the specified type is instantiatable.

    Declaration
    public static bool CanBeInstantiated(Type type)
    Parameters
    Type Name Description
    Type type

    The type to query.

    Returns
    Type Description
    Boolean

    true if the given type is instantiatable.

    Remarks

    Instantiatable is defined as either having a default or implicit constructor or having a registered instantiation method.

    CanBeInstantiated<T>()

    Returns true if type is instantiatable.

    Declaration
    public static bool CanBeInstantiated<T>()
    Returns
    Type Description
    Boolean

    true if type is instantiatable.

    Type Parameters
    Name Description
    T

    The type to query.

    Remarks

    Instantiatable is defined as either having a default or implicit constructor or having a registered instantiation method.

    GetRootType(Type)

    Utility method to return the base type.

    Declaration
    public static Type GetRootType(this Type type)
    Parameters
    Type Name Description
    Type type

    The Type for which we want the base type.

    Returns
    Type Description
    Type

    The base type.

    GetTypeDisplayName(Type)

    Utility method to get the name of a type which includes the parent type(s).

    Declaration
    public static string GetTypeDisplayName(Type type)
    Parameters
    Type Name Description
    Type type

    The Type we want the name of.

    Returns
    Type Description
    String

    The display name of the type.

    Instantiate<T>()

    Creates a new instance of the specified .

    Declaration
    public static T Instantiate<T>()
    Returns
    Type Description
    T

    A new instance of the .

    Type Parameters
    Name Description
    T

    The type we want to create a new instance of.

    Exceptions
    Type Condition
    InvalidOperationException

    The specified has no available instantiation method.

    Instantiate<T>(Type)

    Creates a new instance of the given type type and returns it as .

    Declaration
    public static T Instantiate<T>(Type derivedType)
    Parameters
    Type Name Description
    Type derivedType

    The type we want to create a new instance of.

    Returns
    Type Description
    T

    a new instance of the type.

    Type Parameters
    Name Description
    T

    The type we want to create a new instance of.

    Exceptions
    Type Condition
    ArgumentException

    Thrown when the given type is not assignable to .

    InstantiateArray<TArray>(Int32)

    Creates a new instance of an array with the given count.

    Declaration
    public static TArray InstantiateArray<TArray>(int count = 0)
    Parameters
    Type Name Description
    Int32 count

    The size of the array to instantiate.

    Returns
    Type Description
    TArray

    The array newly created array.

    Type Parameters
    Name Description
    TArray

    The array type to instantiate.

    Exceptions
    Type Condition
    ArgumentException

    Thrown is count is negative or if is not an array type.

    InstantiateArray<TArray>(Type, Int32)

    Creates a new instance of an array with the given type and given count.

    Declaration
    public static TArray InstantiateArray<TArray>(Type derivedType, int count = 0)
    Parameters
    Type Name Description
    Type derivedType

    The type we want to create a new instance of.

    Int32 count

    The size of the array to instantiate.

    Returns
    Type Description
    TArray

    The array newly created array.

    Type Parameters
    Name Description
    TArray

    The array type to instantiate.

    Exceptions
    Type Condition
    ArgumentException

    Thrown is count is negative or if is not an array type.

    SetExplicitInstantiationMethod<T>(Func<T>)

    Sets an explicit instantiation method for the type.

    Declaration
    public static void SetExplicitInstantiationMethod<T>(Func<T> constructor)
    Parameters
    Type Name Description
    Func<T> constructor

    The instantiation method.

    Type Parameters
    Name Description
    T

    The type to set the explicit instantiation method.

    TryInstantiate<T>(out T)

    Creates a new instance of the specified .

    Declaration
    public static bool TryInstantiate<T>(out T instance)
    Parameters
    Type Name Description
    T instance

    When this method returns, contains the created instance, if type instantiation succeeded; otherwise, the default value for T.

    Returns
    Type Description
    Boolean

    true if a new instance of type was created; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to create an instance of.

    TryInstantiate<T>(Type, out T)

    Tries to create a new instance of the given type type and returns it as .

    Declaration
    public static bool TryInstantiate<T>(Type derivedType, out T value)
    Parameters
    Type Name Description
    Type derivedType

    The type we want to create a new instance of.

    T value

    When this method returns, contains the created instance, if type instantiation succeeded; otherwise, the default value for T.

    Returns
    Type Description
    Boolean

    true if a new instance of the given type could be created.

    Type Parameters
    Name Description
    T

    The type we want to create a new instance of.

    TryInstantiateArray<TArray>(Int32, out TArray)

    Tries to create a new instance of an array with the given count.

    Declaration
    public static bool TryInstantiateArray<TArray>(int count, out TArray instance)
    Parameters
    Type Name Description
    Int32 count

    The count the array should have.

    TArray instance

    When this method returns, contains the created instance, if type instantiation succeeded; otherwise, the default value for TArray.

    Returns
    Type Description
    Boolean

    true if the type was instantiated; otherwise, false.

    Type Parameters
    Name Description
    TArray

    The array type.

    Exceptions
    Type Condition
    ArgumentException

    Thrown is count is negative or if is not an array type.

    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023