Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
 public void Bind(MethodGen implementation)
 {
     this.implementation = implementation;
 }
Exemplo n.º 10
0
 public bool Match(MethodGen candidate)
 {
     return(candidate.Name == interfaceMethod.Name &&
            candidate.ReturnType == interfaceMethod.ReturnType &&
            ArrayUtils.Equals(candidate.ParameterTypes, interfaceMethod.ParameterTypes));
 }