Skip to content

Instantly share code, notes, and snippets.

@trxcllnt
Created February 9, 2011 00:55
Show Gist options
  • Save trxcllnt/817661 to your computer and use it in GitHub Desktop.
Save trxcllnt/817661 to your computer and use it in GitHub Desktop.
caches the results from Flash's describeType() call
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);
}
@trxcllnt
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment