public void InvokeBase(params Operand[] args)
        {
            if (cg == null)
            {
                throw new InvalidOperationException(Properties.Messages.ErrConstructorOnlyCall);
            }
            if (chainCalled)
            {
                throw new InvalidOperationException(Properties.Messages.ErrConstructorAlreadyChained);
            }
            if (cg.Type.TypeBuilder.IsValueType)
            {
                throw new InvalidOperationException(Properties.Messages.ErrStructNoBaseCtor);
            }

            ApplicableFunction other = TypeInfo.FindConstructor(cg.Type.BaseType, args);

            if (other == null)
            {
                throw new InvalidOperationException(Properties.Messages.ErrMissingConstructor);
            }

            il.Emit(OpCodes.Ldarg_0);
            other.EmitArgs(this, args);
            il.Emit(OpCodes.Call, (ConstructorInfo)other.Method.Member);
            chainCalled = true;

            // when the chain continues to base, we also need to call the common constructor
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Call, cg.Type.CommonConstructor().GetMethodBuilder());
        }
Esempio n. 2
0
        public void InvokeBase(params Operand[] args)
        {
            if (cg == null)
            {
                throw new InvalidOperationException("This method can be called only for constructor code");
            }
            if (chainCalled)
            {
                throw new InvalidOperationException("Specific chained constructor can be invoked only as the first statement in a constructor");
            }
            if (cg.Type.TypeBuilder.IsValueType)
            {
                throw new InvalidOperationException("Value type constructor cannot invoke a base constructor");
            }

            ApplicableFunction other = TypeInfo.FindConstructor(cg.Type.BaseType, args);

            if (other == null)
            {
                throw new InvalidOperationException("Cannot find constructor");
            }

            il.Emit(OpCodes.Ldarg_0);
            other.EmitArgs(this, args);
            il.Emit(OpCodes.Call, (ConstructorInfo)other.Method.Member);
            chainCalled = true;

            // when the chain continues to base, we also need to call the common constructor
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Call, cg.Type.CommonConstructor().GetMethodBuilder());
        }
        public void InvokeThis(params Operand[] args)
        {
            if (cg == null)
            {
                throw new InvalidOperationException(Properties.Messages.ErrConstructorOnlyCall);
            }
            if (chainCalled)
            {
                throw new InvalidOperationException(Properties.Messages.ErrConstructorAlreadyChained);
            }

            ApplicableFunction other = TypeInfo.FindConstructor(cg.Type, args);

            il.Emit(OpCodes.Ldarg_0);
            other.EmitArgs(this, args);
            il.Emit(OpCodes.Call, (ConstructorInfo)other.Method.Member);
            chainCalled = true;
        }
Esempio n. 4
0
        public void InvokeThis(params Operand[] args)
        {
            if (cg == null)
            {
                throw new InvalidOperationException("This method can be called only for constructor code");
            }
            if (chainCalled)
            {
                throw new InvalidOperationException("Specific chained constructor can be invoked only as the first statement in a constructor");
            }

            ApplicableFunction other = TypeInfo.FindConstructor(cg.Type, args);

            il.Emit(OpCodes.Ldarg_0);
            other.EmitArgs(this, args);
            il.Emit(OpCodes.Call, (ConstructorInfo)other.Method.Member);
            chainCalled = true;
        }