Description
The TypeReflector class allows you to examine the type of an object, and create instancies of objects based on their type.
Important points
- This class has symmetric implementation across all languages supported by the Pip.Services toolkit and used to support dynamic data processing.
- Because all languages have different casing and case sensitivity rules, the TypeReflector class treats all type names as case insensitive.
Static methods
createInstance
Creates an instance of an object type specified by its name and library where it is defined.
See getType See createInstanceByType
static
dynamic createInstance(String name, String library, List args) {
- name: String - an object type name.
- library: String - a library (module) where object type is defined.
- args: List - arguments for the object constructor.
- returns: dynamic - the created object instance.
createInstanceByType
Creates an instance of an object type.
static
dynamic createInstanceByType(Type? type, List? args)
- type: Type? - object type (factory function) to create.
- args: List? - arguments for the object constructor.
- returns: dynamic - created object’s instance.
createInstanceByDescriptor
Creates an instance of an object type specified by a type descriptor.
static
dynamic createInstanceByDescriptor(TypeDescriptor descriptor, List args)
- descriptor: TypeDescriptor - type descriptor that points to an object type
- args: List - arguments for the object constructor.
- returns: dynamic - created object instance.
createInstanceByType
Creates an instance of an object’s type.
static
dynamic createInstanceByType(Type type, List args)
- type: Type - object type (factory function) to create.
- args: List - arguments for the object’s constructor.
- returns: dynamic - created object instance.
getType
Gets an object’s type by its name and library where it is defined.
static
Type? getType(String name, [String library])
- name: String - object type name.
- library: String - library where the type is defined.
- returns: Type? - object type or null is the type wasn’t found.
getTypeByDescriptor
Gets an object’s type by type descriptor.
static
Type? getTypeByDescriptor(TypeDescriptor descriptor)
- descriptor: TypeDescriptor - type descriptor that points to an object type.
- returns: Type? - object type or null is the type wasn’t found.
isPrimitive
Checks if a value has a primitive type.
Primitive types are: numbers, strings, booleans, date and time.
Complex (non-primitive types are): objects, maps and arrays.
See TypeConverter.toTypeCode, TypeCode
static
bool isPrimitive(value)
- value: dynamic - value to check
- returns:bool - true if the value has primitive type and false if value type is complex.
Examples
var descriptor = TypeDescriptor('MyObject', 'mylibrary');
Typeeflector.getTypeByDescriptor(descriptor);
var myObj = TypeReflector.createInstanceByDescriptor(descriptor);
TypeDescriptor.isPrimitive(myObject); // Result: false
TypeDescriptor.isPrimitive(123); // Result: true