Aug 5, 2007

Reflection

            var g = new Demo.Trees.GrannySmith();
            var gt = Demo.Trees.GrannySmith;
            var a = new Array(
            Demo.Trees.Apple,
            Demo.Trees.Tree,
            Demo.Trees.Pine,
            Demo.Trees.IFruitTree,
            Sys.IContainer);

            function OnButton1Click()
            {
            for (var i = 0; i < a.length; i ++)
            {
            if (a[i].isInstanceOfType(g))
            {
            alert(gt.getName() + " is a " + a[i].getName() + ".");
            }
            else alert(gt.getName() + " is not a " + a[i].getName() + ".");
            }
            }

            function OnButton2Click()
            {
            for (var i = 0; i < a.length; i ++)
            {
            if (gt.inheritsFrom(a[i]))
            {
            alert(gt.getName() + " inherits from " + a[i].getName() + ".");
            }
            else alert(gt.getName() + " does not inherit from " + a[i].getName() + ".");
            }
            }

            function OnButton3Click()
            {
            for (var i = 0; i < a.length; i ++)
            {
            if (Type.isInterface(a[i]))
            {
            if (gt.implementsInterface(a[i]))
            {
            alert(gt.getName() + " implements the " + a[i].getName() + " interface.");
            }
            else alert(gt.getName() + " does not implement the " + a[i].getName() + " interface.");
            }
            else alert(a[i].getName() + " is not an interface.");
            }
            }