3
An abstract type that represents a Class.
9
3
An abstract type that represents an Enum.
4
See [Type] for the haXe Reflection API.
15
10
The diffent possible runtime types of a value.
11
See [Type] for the haXe Reflection API.
20
TClass( c : Class<Dynamic> );
26
The haXe Reflection API enables you to retreive informations about any value,
27
Classes and Enums at runtime.
32
Returns the class of an object
34
public static function getClass( o : Dynamic ) : Class untyped {
32
Converts a value to an Enum or returns [null] if the value is not an Enum.
34
public static function toEnum( t : Dynamic ) : Enum untyped {
40
if( t.__ename__ == null )
44
} catch( e : Dynamic ) {
50
Converts a value to a Class or returns [null] if the value is not a Class.
52
public static function toClass( t : Dynamic ) : Class<Dynamic> untyped {
55
if( !t.hasOwnProperty("prototype") )
58
if( t.__name__ == null )
62
} catch( e : Dynamic ) {
68
Returns the class of a value or [null] if this value is not a Class instance.
70
public static function getClass<T>( o : T ) : Class<T> untyped {
36
72
var cname = __global__["flash.utils.getQualifiedClassName"](o);
37
73
if( cname == "null" || cname == "Object" || cname == "int" || cname == "Number" || cname == "Boolean" )
39
75
if( o.hasOwnProperty("prototype") )
41
var c = __global__["flash.utils.getDefinitionByName"](cname);
77
var c = __as__(__global__["flash.utils.getDefinitionByName"](cname),Class);
74
110
// getEnum(Enum) should be null
75
111
if( o.hasOwnProperty("prototype") )
77
var c = __global__["flash.utils.getDefinitionByName"](cname);
113
var c = __as__(__global__["flash.utils.getDefinitionByName"](cname),Class);
97
Returns the super-class of a class
133
Returns the super-class of a class, or null if no super class.
99
public static function getSuperClass( c : Class ) : Class untyped {
135
public static function getSuperClass( c : Class<Dynamic> ) : Class<Dynamic> untyped {
101
137
var cname = __global__["flash.utils.getQualifiedSuperclassName"](c);
102
138
if( cname == "Object" )
104
return __global__["flash.utils.getDefinitionByName"](cname);
140
return __as__(__global__["flash.utils.getDefinitionByName"](cname),Class);
106
142
return c.__super__;
112
Returns the complete name of the class of an object
148
Returns the complete name of a class.
114
public static function getClassName( c : Class ) : String {
150
public static function getClassName( c : Class<Dynamic> ) : String {
118
var name = untyped __global__["flash.utils.getQualifiedClassName"](c);
119
if( name == "flash::FlashXml__" )
154
var str : String = untyped __global__["flash.utils.getQualifiedClassName"](c);
155
return str.split("::").join(".");
123
157
var a : Array<String> = untyped c.__name__;
124
158
return a.join(".");
142
Evaluates a class from a name
176
Evaluates a class from a name. The class must have been compiled
144
public static function resolveClass( name : String ) : Class {
179
public static function resolveClass( name : String ) : Class<Dynamic> {
180
var cl : Class<Dynamic>;
149
cl = __global__["flash.utils.getDefinitionByName"](name);
184
cl = __as__(__global__["flash.utils.getDefinitionByName"](name),Class);
150
185
if( cl.__isenum )
152
187
return cl; // skip test below
259
Creates an instance of the given class with the list of constructor arguments.
261
public static function createInstance<T>( cl : Class<T>, args : Array<Dynamic> ) : T untyped {
263
return switch( args.length ) {
265
case 1: __new__(cl,args[0]);
266
case 2: __new__(cl,args[0],args[1]);
267
case 3: __new__(cl,args[0],args[1],args[2]);
268
case 4: __new__(cl,args[0],args[1],args[2],args[3]);
269
case 5: __new__(cl,args[0],args[1],args[2],args[3],args[4]);
270
default: throw "Too many arguments";
273
var o = { __constructor__ : cl, __proto__ : cl.prototype };
277
return untyped __dollar__call(__dollar__objget(cl,__dollar__hash("new".__s)),cl,args.__neko());
279
if( args.length >= 6 ) throw "Too many arguments";
280
return untyped __new__(cl,args[0],args[1],args[2],args[3],args[4],args[5]);
224
286
Similar to [Reflect.createInstance] excepts that the constructor is not called.
287
This enables you to create an instance without any side-effect.
226
public static function createEmptyInstance( cl : Class ) untyped {
289
public static function createEmptyInstance<T>( cl : Class<T> ) : T untyped {
228
return cl.__construct__.call(null,null);
292
flash.Boot.skip_constructor = true;
294
flash.Boot.skip_constructor = false;
296
} catch( e : Dynamic ) {
297
flash.Boot.skip_constructor = false;
230
302
var o : Dynamic = __new__(_global["Object"]);
231
303
o.__proto__ = cl.prototype;
260
Returns the list of instance fields
332
Returns the list of instance fields.
262
public static function getInstanceFields( c : Class ) : Array<String> {
334
public static function getInstanceFields( c : Class<Dynamic> ) : Array<String> {
264
336
return describe(c,true);
283
Returns the list of class static fields
355
Returns the list of a class static fields.
285
public static function getClassFields( c : Class ) : Array<String> {
357
public static function getClassFields( c : Class<Dynamic> ) : Array<String> {
287
359
var a = describe(c,false);
288
360
a.remove("__construct__");
308
380
Returns all the available constructor names for an enum.
310
382
public static function getEnumConstructs( e : Enum ) : Array<String> {
312
return describe(e,false);
314
var a = Reflect.fields(e);
315
a.remove(__unprotect__("__ename__"));
317
a.remove("prototype");
383
return untyped e.__constructs__;
354
417
case "Boolean": return TBool;
355
418
case "Object": return TObject;
358
var c = __global__["flash.utils.getDefinitionByName"](cname);
422
c = __global__["flash.utils.getDefinitionByName"](cname);
359
423
if( v.hasOwnProperty("prototype") )
363
427
return TClass(c);
364
428
} catch( e : Dynamic ) {
429
if( cname == "builtin.as$0::MethodClosure" || cname.indexOf("-") != -1 )
431
return if( c == null ) TFunction else TClass(c);
368
435
#else (flash || js)
369
436
switch( #if flash __typeof__ #else true __js__("typeof") #end(v) ) {
474
Recursively compare two enums constructors and parameters.
476
public static function enumEq<T>( a : T, b : T ) : Bool untyped {
481
if( a.__enum__ == null || a.tag != b.tag )
483
} catch( e : Dynamic ) {
486
for( i in 0...__dollar__asize(a.args) )
487
if( !enumEq(a.args[i],b.args[i]) )
493
for( i in 0...a.params.length )
494
if( !enumEq(a.params[i],b.params[i]) )
496
} catch( e : Dynamic ) {
502
for( i in 2...a.length )
503
if( !enumEq(a[i],b[i]) )
506
if( e != b.__enum__ || e == null )
513
Returns the constructor of an enum
515
public static function enumConstructor( e : Dynamic ) : String {
517
return new String(e.tag);
526
Returns the parameters of an enum
528
public static function enumParameters( e : Dynamic ) : Array<Dynamic> {
530
return if( e.args == null ) [] else untyped Array.new1(e.args,__dollar__asize(e.args));
532
return if( e.params == null ) [] else e.params;
539
Returns the index of the constructor of an enum
541
public static function enumIndex( e : Dynamic ) : Int {