CK.Reflection.ILGeneratorExtension.RepushActualParameters C# (CSharp) Method

RepushActualParameters() public static method

Emits the optimal IL to push the actual parameter values on the stack (OpCodes.Ldarg_0... OpCodes.Ldarg).
public static RepushActualParameters ( this g, bool startAtArgument0, int count ) : void
g this This object.
startAtArgument0 bool False to skip the very first argument: for a method instance Arg0 is the 'this' object (see ) HasThis and ExplicitThis).
count int Number of parameters to push.
return void
        public static void RepushActualParameters( this ILGenerator g, bool startAtArgument0, int count )
        {
            if( count <= 0 ) return;
            if( startAtArgument0 )
            {
                g.Emit( OpCodes.Ldarg_0 );
                --count;
            }
            if( count > 0 )
            {
                g.Emit( OpCodes.Ldarg_1 );
                if( count > 1 )
                {
                    g.Emit( OpCodes.Ldarg_2 );
                    if( count > 2 )
                    {
                        g.Emit( OpCodes.Ldarg_3 );
                        if( count > 3 )
                        {
                            for( int iParam = 4; iParam <= Math.Min( count, 255 ); ++iParam )
                            {
                                g.Emit( OpCodes.Ldarg_S, (byte)iParam );
                            }
                            if( count > 255 )
                            {
                                for( int iParam = 256; iParam <= count; ++iParam )
                                {
                                    g.Emit( OpCodes.Ldarg, (short)iParam );
                                }
                            }
                        }
                    }
                }
            }
        }