FieldInfo
Runtime reflection utility for extracting field type information from classes.
This class provides a way to retrieve type information about fields at runtime,
which is normally lost due to Haxe's type erasure. It works with Entity subclasses
marked with @fieldInfo
or @autoFieldInfo
metadata, or any class processed by
the FieldInfoMacro build macro.
The field information is extracted from a special _fieldInfo
static field that
is generated at compile time by the FieldInfoMacro. This allows for runtime
introspection of field types, which is useful for serialization, binding systems,
and dynamic property manipulation.
Static Members
types(targetClass: String, ?recursive: Bool = true): ReadOnlyMap<String, String>
Retrieves a map of field names to their type information for a given class.
This method extracts field type information that was generated at compile time by the FieldInfoMacro. The information is cached after the first retrieval for performance.
Example:
var types = FieldInfo.types("myapp.Player");
trace(types.get("health")); // "Float"
trace(types.get("name")); // "String"
Name | Type | Default | Description |
---|---|---|---|
targetClass |
String | The fully qualified class name to extract field info from | |
recursive |
Bool | true |
Whether to include fields from parent classes (default: true) |
Returns | Description |
---|---|
ReadOnlyMap<String, String> | A read-only map of field names to their type strings |
Gets the type information for a specific field of a class.
This is a convenience method that retrieves the type of a single field without having to access the full types map.
Example:
var healthType = FieldInfo.typeOf("myapp.Player", "health");
trace(healthType); // "Float"
Name | Type | Description |
---|---|---|
targetClass |
String | The fully qualified class name containing the field |
field |
String | The name of the field to get type information for |
Returns | Description |
---|---|
String | The type string for the field, or null if the field doesn't exist |
Private Members
fieldInfoMap: Map
Cache of field type information for each class. Key: class name, Value: map of field names to type strings