예제 #1
0
파일: TypeGen.cs 프로젝트: ectacoh/RunSharp
 void DefineMethodOverride(MethodGen methodBody, MethodInfo methodDeclaration)
 {
     foreach (InterfaceImplEntry iie in implementations)
     {
         if (iie.InterfaceMethod.Member == methodDeclaration)
         {
             iie.Bind(methodBody);
             return;
         }
     }
 }
예제 #2
0
        public MethodGen RemoveMethod(string parameterName)
        {
            if (remover == null)
            {
                remover = new MethodGen(owner, "remove_" + name, attrs | MethodAttributes.SpecialName, typeof(void), 0);
                remover.Parameter(type, parameterName);
                eb.SetRemoveOnMethod(remover.GetMethodBuilder());
            }

            return(remover);
        }
예제 #3
0
        public MethodGen AddMethod(string parameterName)
        {
            if (adder == null)
            {
                adder = new MethodGen(owner, "add_" + name, attrs | MethodAttributes.SpecialName, typeof(void), 0);
                adder.Parameter(type, parameterName);
                eb.SetAddOnMethod(adder.GetMethodBuilder());
            }

            return(adder);
        }
예제 #4
0
        public MethodGen AddMethod(string parameterName)
        {
            if (_adder == null)
            {
                LockSignature();
                _adder = new MethodGen(_owner, "add_" + Name, _attrs | MethodAttributes.SpecialName, TypeMapper.MapType(typeof(void)), 0);
                _adder.ImplementedInterface = ImplementedInterface;
                _adder.Parameter(_type, parameterName);
                _eb.SetAddOnMethod(_adder.GetMethodBuilder());
            }

            return(_adder);
        }
예제 #5
0
        public MethodGen Getter()
        {
            if (_getter == null)
            {
                LockSignature();
                _getter = new MethodGen(_owner, "get_" + Name, _attrs | MethodAttributes.SpecialName, _type, 0);
                _getter.ImplementedInterface = ImplementedInterface;
                _getter.CopyParameters(_indexParameters);
                _pb.SetGetMethod(_getter.GetMethodBuilder());
            }

            return(_getter);
        }
예제 #6
0
        public MethodGen Getter()
        {
            if (getter == null)
            {
                LockSignature();
                getter = new MethodGen(owner, "get_" + name, attrs | MethodAttributes.SpecialName, type, 0);
                getter.ImplementedInterface = interfaceType;
                getter.CopyParameters(indexParameters);
                pb.SetGetMethod(getter.GetMethodBuilder());
            }

            return(getter);
        }
예제 #7
0
        public MethodGen MethodImplementation(Type interfaceType, Type returnType, string name)
        {
            if (tb.IsInterface)
            {
                throw new InvalidOperationException("Interface cannot contain explicit interface implementations");
            }

            MethodGen mg = new MethodGen(this, name,
                                         MethodAttributes.Public | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final,
                                         returnType, 0);

            mg.ImplementedInterface = interfaceType;
            return(mg);
        }
예제 #8
0
        public MethodGen Setter()
        {
            if (_setter == null)
            {
                LockSignature();
                _setter = new MethodGen(_owner, "set_" + Name, _attrs | MethodAttributes.SpecialName, TypeMapper.MapType(typeof(void)), 0);
                _setter.ImplementedInterface = ImplementedInterface;
                _setter.CopyParameters(_indexParameters);
                _setter.UncheckedParameter(_type, "value");
                _pb.SetSetMethod(_setter.GetMethodBuilder());
            }

            return(_setter);
        }
예제 #9
0
        public MethodGen Setter()
        {
            if (setter == null)
            {
                LockSignature();
                setter = new MethodGen(owner, "set_" + name, attrs | MethodAttributes.SpecialName, typeof(void), 0);
                setter.ImplementedInterface = interfaceType;
                setter.CopyParameters(indexParameters);
                setter.UncheckedParameter(type, "value");
                pb.SetSetMethod(setter.GetMethodBuilder());
            }

            return(setter);
        }
예제 #10
0
        public MethodGen MethodImplementation(Type interfaceType, Type returnType, string name)
        {
            if (tb.IsInterface)
            {
                throw new InvalidOperationException(Properties.Messages.ErrInterfaceNoExplicitImpl);
            }

            MethodGen mg = new MethodGen(this, name,
                                         MethodAttributes.Private | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final,
                                         returnType, 0);

            mg.ImplementedInterface = interfaceType;
            return(mg);
        }
예제 #11
0
        public MethodGen Method(Type returnType, string name)
        {
            if (mthVis == 0)
            {
                mthVis |= MethodAttributes.Private;
            }
            if (tb.IsInterface)
            {
                mthVirt |= MethodAttributes.Virtual | MethodAttributes.Abstract;
            }

            MethodGen mg = new MethodGen(this, name, mthVis | mthVirt | mthFlags, returnType, implFlags);

            ResetAttrs();
            return(mg);
        }
예제 #12
0
        public MethodGen CommonConstructor()
        {
            if (TypeBuilder.IsValueType)
            {
                throw new InvalidOperationException(Messages.ErrStructNoDefaultCtor);
            }
            if (TypeBuilder.IsInterface)
            {
                throw new InvalidOperationException(Messages.ErrInterfaceNoCtor);
            }

            if (_commonCtor == null)
            {
                _commonCtor = new MethodGen(this, "$$ctor", 0, TypeMapper.MapType(typeof(void)), 0).LockSignature();
            }

            return(_commonCtor);
        }
예제 #13
0
        public MethodGen CommonConstructor()
        {
            if (tb.IsValueType)
            {
                throw new InvalidOperationException(Properties.Messages.ErrStructNoDefaultCtor);
            }
            if (tb.IsInterface)
            {
                throw new InvalidOperationException(Properties.Messages.ErrInterfaceNoCtor);
            }

            if (commonCtor == null)
            {
                commonCtor = new MethodGen(this, "$$ctor", 0, typeof(void), 0).LockSignature();
            }

            return(commonCtor);
        }
예제 #14
0
        public MethodGen CommonConstructor()
        {
            if (tb.IsValueType)
            {
                throw new InvalidOperationException("Value types cannot have default constructors");
            }
            if (tb.IsInterface)
            {
                throw new InvalidOperationException("Interface cannot define a constructor");
            }

            if (commonCtor == null)
            {
                commonCtor = new MethodGen(this, "$$ctor", 0, typeof(void), 0).LockSignature();
            }

            return(commonCtor);
        }
예제 #15
0
        internal MethodAttributes PreprocessAttributes(MethodGen mg, MethodAttributes attrs)
        {
            bool requireVirtual = false;

            foreach (InterfaceImplEntry implEntry in implementations)
            {
                if (!implEntry.IsBound && implEntry.Match(mg))
                {
                    implEntry.Bind(mg);
                    requireVirtual = true;
                }
            }

            if (requireVirtual && ((attrs & MethodAttributes.Virtual) == 0))
            {
                // create an exclusive VTable entry for the method
                attrs |= MethodAttributes.Virtual | MethodAttributes.NewSlot | MethodAttributes.Final;
            }

            return(attrs);
        }
예제 #16
0
 public void Bind(MethodGen implementation)
 {
     BoundMethod = implementation;
 }
예제 #17
0
 public void Bind(MethodGen implementation)
 {
     this.implementation = implementation;
 }
예제 #18
0
 public bool Match(MethodGen candidate)
 {
     return(candidate.Name == interfaceMethod.Name &&
            candidate.ReturnType == interfaceMethod.ReturnType &&
            ArrayUtils.Equals(candidate.ParameterTypes, interfaceMethod.ParameterTypes));
 }
예제 #19
0
 public void setImplementation2(MethodGen mg)
 {
     implementations.ToArray()[1].Bind(mg);
 }