TriAxis.RunSharp.CodeGen.EmitCallHelper C# (CSharp) Method

EmitCallHelper() protected method

protected EmitCallHelper ( MethodBase mth, Operand target ) : void
mth System.Reflection.MethodBase
target Operand
return void
        protected internal void EmitCallHelper(MethodBase mth, Operand target)
        {
            MethodInfo mi = mth as MethodInfo;
            if (mi != null)
            {
                bool suppressVirtual = ((object)target != null && target.SuppressVirtual) || mi.IsStatic || (((object)target != null) 
                    && (target.GetReturnType(TypeMapper).IsValueType|| target.GetReturnType(TypeMapper).IsArray) && !mi.IsVirtual);
                
                if (!suppressVirtual && (object)target != null && target.GetReturnType(TypeMapper).IsValueType && mi.IsVirtual)
                {
                    IL.Emit(OpCodes.Constrained, target.GetReturnType(TypeMapper));
                }
                //Console.WriteLine("Emitting " + mth + ", using " + (suppressVirtual ? "call" : "callvirt"));
                IL.Emit(suppressVirtual ? OpCodes.Call : OpCodes.Callvirt, mi);
                return;
            }

            ConstructorInfo ci = mth as ConstructorInfo;
            if (ci != null)
            {
                IL.Emit(OpCodes.Call, ci);
                return;
            }

            throw new ArgumentException(Properties.Messages.ErrInvalidMethodBase, nameof(mth));
        }
    }

Usage Example

Example #1
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);
        }
All Usage Examples Of TriAxis.RunSharp.CodeGen::EmitCallHelper