Beispiel #1
0
        internal void Register(MethodGen method)
        {
            if (owner.AssemblyBuilder.EntryPoint == null && method.Name == "Main" && method.IsStatic && (
                    method.ParameterCount == 0 ||
                    (method.ParameterCount == 1 && method.ParameterTypes[0] == typeof(string[]))))
            {
                owner.AssemblyBuilder.SetEntryPoint(method.GetMethodBuilder());
            }

            // match explicit interface implementations
            if (method.ImplementedInterface != null)
            {
                foreach (IMemberInfo mi in TypeInfo.Filter(TypeInfo.GetMethods(method.ImplementedInterface), method.Name, false, false, true))
                {
                    if (ArrayUtils.Equals(mi.ParameterTypes, method.ParameterTypes))
                    {
                        DefineMethodOverride(method, (MethodInfo)mi.Member);
                        return;
                    }
                }

                throw new MissingMethodException(Properties.Messages.ErrMissingMethod);
            }

            methods.Add(method);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #4
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);
        }
Beispiel #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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #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);
        }
Beispiel #9
0
        public override void EmitGet(CodeGen g)
        {
            if (getter == null)
            {
                base.EmitGet(g);
            }

            if (indexParameters.Count != 0)
            {
                throw new InvalidOperationException("Cannot access indexed property without indexes");
            }

            if (!IsStatic && (g.Context.IsStatic || g.Context.OwnerType != owner.TypeBuilder))
            {
                throw new InvalidOperationException("The property is accessed from an invalid context");
            }

            g.IL.Emit(OpCodes.Ldarg_0);
            g.EmitCallHelper(getter.GetMethodBuilder(), null);
        }
Beispiel #10
0
        internal override void EmitGet(CodeGen g)
        {
            if (getter == null)
            {
                base.EmitGet(g);
            }

            if (indexParameters.Count != 0)
            {
                throw new InvalidOperationException(Properties.Messages.ErrMissingPropertyIndex);
            }

            if (!IsStatic && (g.Context.IsStatic || g.Context.OwnerType != owner.TypeBuilder))
            {
                throw new InvalidOperationException(Properties.Messages.ErrInvalidPropertyContext);
            }

            g.IL.Emit(OpCodes.Ldarg_0);
            g.EmitCallHelper(getter.GetMethodBuilder(), null);
        }
Beispiel #11
0
        protected internal override void EmitGet(CodeGen g)
        {
            OperandExtensions.SetLeakedState(this, false);
            if (_getter == null)
            {
                base.EmitGet(g);
            }

            if (_indexParameters.Count != 0)
            {
                throw new InvalidOperationException(Properties.Messages.ErrMissingPropertyIndex);
            }

            if (!IsStatic && (g.Context.IsStatic || g.Context.OwnerType != _owner.TypeBuilder))
            {
                throw new InvalidOperationException(Properties.Messages.ErrInvalidPropertyContext);
            }

            g.IL.Emit(OpCodes.Ldarg_0);
            g.EmitCallHelper(_getter.GetMethodBuilder(), null);
        }