Class TypeConstruction
Helper class to create new instances for given types.
Namespace: Unity.Properties.Editor
Syntax
public static class TypeConstruction
Methods
CanBeConstructed(Type)
Returns true if the specified type is constructable.
Declaration
public static bool CanBeConstructed(Type type)
Parameters
| Type | Name | Description | 
|---|---|---|
| Type | type | The type to query.  | 
Returns
| Type | Description | 
|---|---|
| Boolean | true if the given type is constructable.  | 
Remarks
Constructable is defined as either having a default or implicit constructor or having a registered construction method.
CanBeConstructed<T>()
Returns true if type 
Declaration
public static bool CanBeConstructed<T>()
Returns
| Type | Description | 
|---|---|
| Boolean | true if type   | 
Type Parameters
| Name | Description | 
|---|---|
| T | The type to query.  | 
Remarks
Constructable is defined as either having a default or implicit constructor or having a registered construction method.
CanBeConstructedFromDerivedType<T>()
Returns true if type 
Declaration
public static bool CanBeConstructedFromDerivedType<T>()
Returns
| Type | Description | 
|---|---|
| Boolean | true if type   | 
Type Parameters
| Name | Description | 
|---|---|
| T | The type to query.  | 
Remarks
Constructable is defined as either having a default or implicit constructor or having a registered construction method.
Construct<TType>()
Constructs a new instance of the specified 
Declaration
public static TType Construct<TType>()
Returns
| Type | Description | 
|---|---|
| TType | A new instance of the   | 
Type Parameters
| Name | Description | 
|---|---|
| TType | The type we want to create a new instance of.  | 
Construct<TType>(Type)
Constructs a new instance of the given type type and returns it as 
Declaration
public static TType Construct<TType>(Type derivedType)
Parameters
| Type | Name | Description | 
|---|---|---|
| Type | derivedType | The type we want to create a new instance of.  | 
Returns
| Type | Description | 
|---|---|
| TType | a new instance of the   | 
Type Parameters
| Name | Description | 
|---|---|
| TType | The type we want to create a new instance of.  | 
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown when the given type is not assignable to   | 
ConstructArray<TArray>(Int32)
Construct a new instance of an array with the given count.
Declaration
public static TArray ConstructArray<TArray>(int count = 0)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | count | The size of the array to construct.  | 
Returns
| Type | Description | 
|---|---|
| TArray | The array newly constructed array.  | 
Type Parameters
| Name | Description | 
|---|---|
| TArray | The array type to construct.  | 
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown is count is negative or if   | 
GetAllConstructableTypes(Type)
Returns a list of all the constructable types from the provided type.
Declaration
public static IEnumerable<Type> GetAllConstructableTypes(Type type)
Parameters
| Type | Name | Description | 
|---|---|---|
| Type | type | The type to query.  | 
Returns
| Type | Description | 
|---|---|
| IEnumerable<Type> | A list of all the constructable types from the provided type.  | 
GetAllConstructableTypes(Type, List<Type>)
Adds all the constructable types from the provided type to the given list.
Declaration
public static void GetAllConstructableTypes(Type type, List<Type> result)
Parameters
| Type | Name | Description | 
|---|---|---|
| Type | type | The type to query.  | 
| List<Type> | result | List to contain the results.  | 
GetAllConstructableTypes<TType>()
Returns a list of all the constructable types from the 
Declaration
public static IEnumerable<Type> GetAllConstructableTypes<TType>()
Returns
| Type | Description | 
|---|---|
| IEnumerable<Type> | A list of all the constructable types from the   | 
Type Parameters
| Name | Description | 
|---|---|
| TType | The type to query.  | 
GetAllConstructableTypes<TType>(List<Type>)
Adds all the constructable types from the 
Declaration
public static void GetAllConstructableTypes<TType>(List<Type> result)
Parameters
| Type | Name | Description | 
|---|---|---|
| List<Type> | result | List to contain the results.  | 
Type Parameters
| Name | Description | 
|---|---|
| TType | The type to query.  | 
SetExplicitConstructionMethod<TType>(TypeConstruction.ConstructorMethod<TType>)
Sets an explicit construction method for the 
Declaration
public static void SetExplicitConstructionMethod<TType>(TypeConstruction.ConstructorMethod<TType> constructor)
Parameters
| Type | Name | Description | 
|---|---|---|
| TypeConstruction.ConstructorMethod<TType> | constructor | The construction method.  | 
Type Parameters
| Name | Description | 
|---|---|
| TType | The type to set the explicit construction method.  | 
TryConstruct<TType>(out TType)
Constructs a new instance of the specified 
Declaration
public static bool TryConstruct<TType>(out TType instance)
Parameters
| Type | Name | Description | 
|---|---|---|
| TType | instance | When this method returns, contains the created instance, if type construction succeeded; otherwise, the default value for   | 
Returns
| Type | Description | 
|---|---|
| Boolean | true if a new instance of type   | 
Type Parameters
| Name | Description | 
|---|---|
| TType | The type to create an instance of.  | 
TryConstruct<TType>(Type, out TType)
Tries to constructs a new instance of the given type type and returns it as 
Declaration
public static bool TryConstruct<TType>(Type derivedType, out TType value)
Parameters
| Type | Name | Description | 
|---|---|---|
| Type | derivedType | The type we want to create a new instance of.  | 
| TType | value | When this method returns, contains the created instance, if type construction 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 | 
|---|---|
| TType | The type we want to create a new instance of.  | 
TryConstructArray<TArray>(Int32, out TArray)
Tries to construct a new instance of an array with the given count.
Declaration
public static bool TryConstructArray<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 construction succeeded; otherwise, the default value for   | 
Returns
| Type | Description | 
|---|---|
| Boolean | true if the type was constructed; otherwise, false.  | 
Type Parameters
| Name | Description | 
|---|---|
| TArray | The array type.  | 
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown is count is negative or if   | 
TrySetExplicitConstructionMethod<TType>(TypeConstruction.ConstructorMethod<TType>)
Sets the explicit construction method for the 
Declaration
public static bool TrySetExplicitConstructionMethod<TType>(TypeConstruction.ConstructorMethod<TType> constructor)
Parameters
| Type | Name | Description | 
|---|---|---|
| TypeConstruction.ConstructorMethod<TType> | constructor | The construction method.  | 
Returns
| Type | Description | 
|---|---|
| Boolean | true if the constructor was set; otherwise, false.  | 
Type Parameters
| Name | Description | 
|---|---|
| TType | The type to set the explicit construction method.  | 
TryUnsetExplicitConstructionMethod<TType>(TypeConstruction.ConstructorMethod<TType>)
Un-sets the explicit construction method for the 
Declaration
public static bool TryUnsetExplicitConstructionMethod<TType>(TypeConstruction.ConstructorMethod<TType> constructor)
Parameters
| Type | Name | Description | 
|---|---|---|
| TypeConstruction.ConstructorMethod<TType> | constructor | The construction method.  | 
Returns
| Type | Description | 
|---|---|
| Boolean | true if the constructor was unset; otherwise, false.  | 
Type Parameters
| Name | Description | 
|---|---|
| TType | The type to set the explicit construction method.  | 
Remarks
An explicit construction method can only be unset if it was previously set with the same instance.
UnsetExplicitConstructionMethod<TType>(TypeConstruction.ConstructorMethod<TType>)
Un-sets the explicit construction method for the 
Declaration
public static void UnsetExplicitConstructionMethod<TType>(TypeConstruction.ConstructorMethod<TType> constructor)
Parameters
| Type | Name | Description | 
|---|---|---|
| TypeConstruction.ConstructorMethod<TType> | constructor | The construction method.  | 
Type Parameters
| Name | Description | 
|---|---|
| TType | The type to set the explicit construction method.  | 
Remarks
An explicit construction method can only be unset if it was previously set with the same instance.