Created
December 10, 2014 03:22
-
-
Save siratama/4f46732f912ec031d8d1 to your computer and use it in GitHub Desktop.
Haxe abstract class decision and creation by Type.createInstance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dango_itimi.utils; | |
using com.dango_itimi.utils.TypeUtil; | |
class TypeUtil | |
{ | |
public static function isAbstract(cls:Class<Dynamic>):Bool | |
{ | |
var array = Type.getClassFields(cls); | |
for (string in array) | |
{ | |
if(string == "_new") return true; | |
} | |
return false; | |
} | |
//cls contains abstract class | |
public static function createInstance<T>(cls:Class<T>, args:Array<Dynamic>):T | |
{ | |
return !cls.isAbstract() ? | |
Type.createInstance(cast cls, args): | |
Type.createInstance(cast cls, args)._new(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment