ObjectFactory Class
Namespace: PTS.Reflection
Assembly: PTS.Reflection.dll
Static object instance factory.
Syntax
public static class ObjectFactory
Inheritance
Remarks
Provides faster alternative to native Activator methods.
Methods
Create(Type)
Create a new object instance of the specified type.
Declaration
public static object Create(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | Type of the object instance to create. |
Returns
Type | Description |
---|---|
System.Object | A new object instance of specified type. |
Create<TType>(Type)
Create a new casted object instance of the specified type.
Declaration
public static TType Create<TType>(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | Type of the object instance to create. |
Returns
Type | Description |
---|---|
TType | A new casted object instance of specified type. |
Type Parameters
Name | Description |
---|---|
TType | Type the created object will be casted to. |
CreateGeneric(Type, Type[])
Creates an instance of a generic type with specified type parameters.
Declaration
public static object CreateGeneric(Type genericTypeDefinition, params Type[] typeArguments)
Parameters
Type | Name | Description |
---|---|---|
System.Type | genericTypeDefinition | Generic type definition to construct the new generic type instance from. |
System.Type[] | typeArguments | Type arguments used to create the generic type object instance. |
Returns
Type | Description |
---|---|
System.Object |
CreateMany(Type[])
Create a collection of new object instances of the specified type.
Declaration
public static object[] CreateMany(Type[] types)
Parameters
Type | Name | Description |
---|---|---|
System.Type[] | types | Types of the object instances to create. |
Returns
Type | Description |
---|---|
System.Object[] | A collection of new object instances of specified type. |
CreateMany<TType>(Type[])
Create a collection of new casted object instances of the specified type.
Declaration
public static TType[] CreateMany<TType>(Type[] types)
Parameters
Type | Name | Description |
---|---|---|
System.Type[] | types | Types of the object instances to create. |
Returns
Type | Description |
---|---|
TType[] | A collection of new casted object instances of specified type. |
Type Parameters
Name | Description |
---|---|
TType | Type the created objects will be casted to. |