[Type] Reflector
Part of: mobl::reflect
Inherits from: mobl::Object
Reflector
is a type with only static methods that can be use to reflect over objects, e.g. get all its properties, get and set values and so on.
Static methods
getProperties(obj : Object) : [String]
Returns a list of property names for an object.
Example:
Reflector.getProperties(DateTime);
// -> ["parse", "fromTimeStamp", "create"]
Reflector.getProperties(Dynamic(name="Zef", age=27));
// -> ["name", "age"]
get(obj : Object, property : String) : Dynamic
Reads a given property and returns its value as Dynamic value.
Example:
var t = Task(name="First task"); Reflector.get(t, "name") // -> "First Task"
set(obj : Object, property : String, value : Object)
Sets a the property
of object obj
to value
.
Example:
var t = Task(name="First task"); Reflector.set(t, "name", "Second task");
isArray(obj : Object) : Bool
Returns whether the passed object is of type Array.
Example:
Reflector.isArray([1, 2, 3]) // -> true
Reflector.isArray(1) // -> false
isNum(obj : Object) : Bool
Returns whether the passed object is of type Num.
Example:
Reflector.isNum(2) // -> true
Reflector.isNum("foo") // -> false
Reflector.isNum("2") // -> false
isBool(obj : Object) : Bool
Returns whether the passed object is of type Bool.
Example:
Reflector.isBool(true) // -> true
Reflector.isBool(false) // -> true
Reflector.isBool("hello") // -> false
isString(obj : Object) : Bool
Returns whether the passed object is of type String.
Example:
Reflector.isString("hello") // -> true
Reflector.isString(false) // -> false
mobl/reflect/reflector.txt · Last modified: 2013/10/01 02:28 (external edit)