Beispiel #1
0
        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());
        }
Beispiel #2
0
        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;
        }