Class TypeUtility
Utility class around Type.
Inherited Members
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
Declaration
public static bool CanBeInstantiated<T>()
Returns
Type | Description |
---|---|
Boolean | true if type |
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 |
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 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 |
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 |
SetExplicitInstantiationMethod<T>(Func<T>)
Sets an explicit instantiation method for the
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 |
Returns
Type | Description |
---|---|
Boolean | true if a new instance of type |
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 |
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 |
Returns
Type | Description |
---|---|
Boolean |
Type Parameters
Name | Description |
---|---|
TArray | The array type. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown is count is negative or if |