Created
February 9, 2011 00:55
-
-
Save trxcllnt/817661 to your computer and use it in GitHub Desktop.
caches the results from Flash's describeType() call
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 org.tinytlf.utils | |
{ | |
import flash.utils.*; | |
public function reflect(type:Object, refreshCache:Boolean = false):XML | |
{ | |
const typeCache:Dictionary = ReflectionCache.cache; | |
if(!(type is Class)) | |
{ | |
if(type is Proxy) | |
type = getDefinitionByName(getQualifiedClassName(type)) as Class; | |
else if(type is Number) | |
type = Number; | |
else | |
type = type.constructor as Class; | |
} | |
if(refreshCache || typeCache[type] == null) | |
typeCache[type] = flash.utils.describeType(type); | |
return typeCache[type]; | |
} | |
} | |
import flash.utils.Dictionary; | |
internal class ReflectionCache | |
{ | |
public static const cache:Dictionary = new Dictionary(false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I may be totally off base here (and I thought hard about this before posting), but I don't see a use case for reflecting on anything other than the Class. Feel free to smack me if I'm wrong.
When you call describeType() on an instance, it leaves out static members of the Class, which I can't see being desirable if we're caching the results.
For what it's worth, agree that the implementation of the method is "different" than what the method describes, but only because this impl is the superior way of reflecting on the type.