Exemple #1
0
        // X:\jsc.svn\examples\javascript\async\test\TestBytesFromSemaphore\TestBytesFromSemaphore\Application.cs

        public virtual bool IsAssignableFrom(Type TargetType)
        {
            // jsc rewriter could replace it with is operator for static cases?

            // X:\jsc.svn\examples\javascript\test\TestIsAssignableFrom\TestIsAssignableFrom\Application.cs
            // X:\jsc.svn\examples\javascript\test\TestSwitchToIFrame\TestSwitchToIFrame\Application.cs

            // IAsyncStateMachine vs c

            //o33aimgYBj_aJ1Gk6clAOrw.Interfaces =
            //  {
            //    f7G82WqfyzOLoZ_b8v0KVxw: 1
            //  };

            //// TestIsAssignableFrom.foo
            //function o33aimgYBj_aJ1Gk6clAOrw() { }
            //o33aimgYBj_aJ1Gk6clAOrw.TypeName = "foo";
            //  o33aimgYBj_aJ1Gk6clAOrw.Assembly = YQ3YcnWoDE6CyQ7lsi20IQ;

            var TargetTypeHandle = TargetType.TypeHandle;
            var prototype        = (object)TargetTypeHandle.Value;

            if (prototype == null)
            {
                //throw new Exception("IsAssignableFrom:482 prototype null " + new { TargetType });
                return(false);
            }

            var prototype_constructor = Expando.InternalGetMember(prototype, "constructor");

            if (prototype_constructor == null)
            {
                return(false);
            }


            //0:4257ms { Name = foo, prototype_constructor_TypeName =  }

            var prototype_constructor_Interfaces = Expando.InternalGetMember(prototype_constructor, "Interfaces");

            if (prototype_constructor_Interfaces == null)
            {
                return(false);
            }

            // now if we are an interface, then there will be a match

            var this_prototype = (object)this.TypeHandle.Value;

            if (this_prototype == null)
            {
                return(false);
            }
            //throw new Exception("IsAssignableFrom:501 this_prototype null " + new { TargetType });

            var this_prototype_constructor = Expando.InternalGetMember(this_prototype, "constructor");

            // we should not compare names, we should resolve and compare refs

            var any = Expando.InternalGetMemberNames(prototype_constructor_Interfaces).AsEnumerable().Any(
                item =>
            {
                dynamic self = Native.self;
                object value = self[item];

                if (value == this_prototype_constructor)
                {
                    //Console.WriteLine(new { item, f });
                    return(true);
                }
                return(false);
            }
                );


            return(any);
        }