FieldMeta
Runtime reflection utility for accessing field metadata.
This class provides methods to query metadata annotations on fields at runtime. In Haxe, metadata (annotations starting with @) can be attached to fields, methods, and classes at compile time. This utility leverages Haxe's RTTI (Runtime Type Information) system to access that metadata at runtime.
The class maintains internal caches for performance and supports both recursive (including parent classes) and non-recursive metadata lookup.
Common use cases include:
- Checking if a field has specific metadata annotations
- Retrieving metadata values for serialization/deserialization
- Implementing custom binding or validation systems
Example:
(0, 100)
public var health:Float = 100;
// At runtime:
var hasSer = FieldMeta.hasMeta(Player, "health", "serialize"); // true
var meta = FieldMeta.getMeta(Player, "health");
var range = meta.get("range"); // [0, 100]
Static Members
Checks if a field has a specific metadata annotation (class-based overload).
Name | Type | Default | Description |
---|---|---|---|
clazz |
Class<Dynamic> | The class containing the field | |
field |
String | The name of the field to check | |
meta |
String | The metadata name to look for | |
recursive |
Bool | true |
Whether to include parent classes in the search (default: true) |
Returns | Description |
---|---|
Bool | True if the field has the specified metadata |
getMeta(clazz: Class<Dynamic>, field: String, ?recursive: Bool = true): ReadOnlyMap<String, Dynamic>
Retrieves all metadata for a field (class-based overload).
Returns a map containing all metadata annotations and their values for the specified field. The map keys are metadata names and values are the metadata parameters (if any).
Name | Type | Default | Description |
---|---|---|---|
clazz |
Class<Dynamic> | The class containing the field | |
field |
String | The name of the field to get metadata for | |
recursive |
Bool | true |
Whether to include parent classes in the search (default: true) |
Returns | Description |
---|---|
ReadOnlyMap<String, Dynamic> | A read-only map of metadata names to values, or null if field not found |
Private Members
metaMap: Map
Cache for non-recursive metadata lookups. Structure: className -> fieldName -> metaName -> metaValue
metaMapRecursive: Map
Cache for recursive metadata lookups (including parent classes). Structure: className -> fieldName -> metaName -> metaValue