This is an automated email from the ASF dual-hosted git repository.
harbs pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/royale-docs.git
The following commit(s) were added to refs/heads/master by this push:
new 5586933 Added more reflection details
5586933 is described below
commit 55869335fe66835f602a5c62bf9239b74af0a0cf
Author: Harbs <[email protected]>
AuthorDate: Mon Jan 3 23:59:39 2022 +0200
Added more reflection details
---
features/reflection-introspection.md | 75 +++++++++++++++++++++++++++++++++++-
1 file changed, 74 insertions(+), 1 deletion(-)
diff --git a/features/reflection-introspection.md
b/features/reflection-introspection.md
index ae40f14..57b1d91 100644
--- a/features/reflection-introspection.md
+++ b/features/reflection-introspection.md
@@ -23,17 +23,67 @@ permalink: /features/reflection-introspection
Finding the class and details of an object
-ActionScript 3.0 supports class reflection and introspection using the
following functions in the `flash.utils` package:
+Reflection and introspection are in the Royale `Reflection` library.
+Royale supports class reflection and introspection using the following
functions in the `org.apache.royale.reflection` package:
+
+- registerClassAlias
+- getAliasByClass
+- getClassByAlias
+- getAncestry
+- getClosureQualifiedName
- getQualifiedClassName
- getQualifiedSuperclassName
- getDefinitionByName
+- getDynamicFields
+- isDynamicObject
- describeType
## Reflection
Use reflection to find the class of an object.
+### registerClassAlias
+Sets up an alias mapping for serialization/deserialization purposes This can
be auto-generated by the Royale compiler when using class level metadata e.g.
[RemoteClass(alias='someAlias')]
+
+```
+registerClassAlias("someAlias", com.acme.Foo);
+```
+
+### getAliasByClass
+
+Retrieves a an alias for a class, based on an alias mapping, previously
registered with registerClassAlias, or possibly using
[RemoteClass(alias='someAlias')] metadata.
+
+```
+var alias:String = getAliasByClass(com.acme.Foo);
+trace(alias); // Displays the alias name (i.e. someAlias)
+```
+
+### getClassByAlias
+Retrieves a class based on an alias mapping, previously registered with
registerClassAlias, or possibly using [RemoteClass(alias='someAlias')] metadata.
+
+```
+var classRef:Class = getClassByAlias("someAlias");
+trace(classRef); // Displays the class (i.e. com.acme.Foo)
+```
+
+### getAncestry
+A utility function to return ancestry (base classes) as a set of qualified
names.
+
+```
+var ancestry:Array = getAncestry(org.apache.royale.core.UIBase);
+trace(ancestry.join(\n))// will output a list of the inheritance tree
+```
+
+### getClosureQualifiedName
+Returns the qualified name of a closure instance. Using this to compare
against is recommended when checking for closures. It could insulate against
future changes or future variation between targets.
+
+(this is not generally used by an end user)
+
+```
+trace(getClosureQualifiedName());// outputs "builtin.as$0.MethodClosure"
+```
+
### getQualifiedClassName
Pass to `getQualifiedClassName()` a reference to an object, and it returns the
object's fully qualified class name:
@@ -77,6 +127,29 @@ var classReference:Class =
Class(getDefinitionByName(className));
var instance:Object = new classReference();
```
+### getDynamicFields
+A utility method to check if an object is dynamic (i.e. can have non-sealed
members added or deleted).
+
+Note that static class objects are always dynamic, as are (static) Interface
Objects
+
+The function takes four parameters:
+
+1. The class or instance to check for dynamic fields
+2. A Function. An optional function for which takes a single String argument
and returns true to include that specific field in the results. If it returns
false, that property is excluded. Defaults to null, which applies no filtering
and returns all detected properties.
+3. A Boolean. An optional check to verify that the inspect parameter is
dynamic before inspecting it for dynamic properties. This should normally be
left at its default value of true. If it is known that the object is dynamic
before calling this method, setting this to false could improve performance in
performance-sensitive code. The results of calling this method on non-dynamic
objects may be less reliable or less consistent across target platforms if
checkFirst is false
+4. An Boolean. If true, numeric fields will be returned as numeric values
+
+It returns the dynamic fields as Strings in an Array.
+### isDynamicObject
+A utility method to check if an object is dynamic (can have non-sealed members
added or deleted).
+
+Note that static class objects are always dynamic, as are Interface Objects
+
+```
+if(isDynamicObject(myObject)){
+ trace("yay!);
+}
+```
## Class introspection