从静态方法类反思 [英] Class reflection from a static method
问题描述
我使用的是优秀的 org.as3commons.reflect 和 org.as3commons.lang 图书馆遇到了阻碍。我有一个静态方法在我的一个类,需要做反思的及其的类。在反映图书馆有Type.forClass(clazz所:类)的静态方法,它显然需要一个类变量。没有这的静态方法/ code所以现在我需要知道,如果有一种方法来获取其中我的静态方法被调用的类允许的关键字。
I am using the excellent org.as3commons.reflect and org.as3commons.lang libraries and have hit a snag. I have a static method in one of my classes that needs to do reflection on its class. The reflect library has a Type.forClass(clazz:Class) static method that clearly requires a Class variable. There is no this keyword allowed in static methods/code so now I need to know if there is a way to get the class for which my static method is being called.
我需要的东西,将工作在Flash播放器的非调试版本,所以任何的Error.getStackTrace()的技巧将无法正常工作。太糟糕了,没有堆栈跟踪是正常的虚拟机可用。
I need something that will work in the non-debug version of Flash player, so any Error.getStackTrace() tricks won't work. Too bad no stack trace is available in the normal VM.
import org.as3commons.lang.ClassUtils;
import org.as3commons.reflect.Type;
protected static function doReflection(): void
{
var aClass: Class = ClassUtils.forInstance(this); // this not allowed in static methods
var ct: Type = Type.forClass(aClass);
// do stuff with type
}
我放弃了搜索在谷歌和其他网站;总是最终获得教程和技巧任何有关静态成员,性能问题的所有的只是我所期待的。
I gave up searching on Google and other sites; always ended up getting tutorials and tips on everything related to static members, performance issues, everything except what I am looking for.
总之,我想缓存一个关于类的静态成员一堆东西给类被实例化,每次节省不必要的工作。
Overall, I want to cache a bunch of things about the class in static members to save unnecessary work each time the class gets instantiated.
任何帮助将是AP preciated。
Any help would be appreciated.
推荐答案
怎么样通过引用实例,你需要为静态方法的参数?
what about passing a reference to the instance you need as an argument of static method?
这篇关于从静态方法类反思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!