private static void AddDefaultInterfaceMethods(DynamicTypeWrapper.FinishContext context, MethodWrapper[] methodList, TypeBuilder tb)
        {
            // we use special name to hide these from Java reflection
            const MethodAttributes attr    = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.NewSlot | MethodAttributes.Final | MethodAttributes.SpecialName;
            TypeWrapperFactory     factory = context.TypeWrapper.GetClassLoader().GetTypeWrapperFactory();

            foreach (MethodWrapper mw in methodList)
            {
                if (!mw.IsAbstract)
                {
                    MethodBuilder mb = mw.GetDefineMethodHelper().DefineMethod(factory, tb, mw.Name, attr);
                    if (mw.Name != mw.RealName)
                    {
                        tb.DefineMethodOverride(mb, (MethodInfo)mw.GetMethod());
                    }
                    DynamicTypeWrapper.FinishContext.EmitCallDefaultInterfaceMethod(mb, mw);
                }
                else if (IsObjectMethod(mw))
                {
                    MethodBuilder mb = mw.GetDefineMethodHelper().DefineMethod(factory, tb, mw.Name, attr);
                    if (mw.Name != mw.RealName)
                    {
                        tb.DefineMethodOverride(mb, (MethodInfo)mw.GetMethod());
                    }
                    CodeEmitter ilgen = CodeEmitter.Create(mb);
                    for (int i = 0, count = mw.GetParameters().Length; i <= count; i++)
                    {
                        ilgen.EmitLdarg(i);
                    }
                    CoreClasses.java.lang.Object.Wrapper.GetMethodWrapper(mw.Name, mw.Signature, false).EmitCallvirt(ilgen);
                    ilgen.Emit(OpCodes.Ret);
                    ilgen.DoEmit();
                }
            }
        }
예제 #2
0
        internal TypeWrapperFactory GetTypeWrapperFactory()
        {
            if (factory == null)
            {
                lock (this)
                {
                    if (factory == null)
                    {
#if CLASSGC
                        if (dynamicAssemblies == null)
                        {
                            Interlocked.CompareExchange(ref dynamicAssemblies, new ConditionalWeakTable <Assembly, ClassLoaderWrapper>(), null);
                        }
                        typeToTypeWrapper = new Dictionary <Type, TypeWrapper>();
                        DynamicClassLoader instance = DynamicClassLoader.Get(this);
                        dynamicAssemblies.Add(instance.ModuleBuilder.Assembly.ManifestModule.Assembly, this);
                        this.factory = instance;
#else
                        factory = DynamicClassLoader.Get(this);
#endif
                    }
                }
            }
            return(factory);
        }