当前位置: 首页>>代码示例>>C#>>正文


C# LocalBuilder.GetMethodBuilder方法代码示例

本文整理汇总了C#中System.Reflection.Emit.LocalBuilder.GetMethodBuilder方法的典型用法代码示例。如果您正苦于以下问题:C# LocalBuilder.GetMethodBuilder方法的具体用法?C# LocalBuilder.GetMethodBuilder怎么用?C# LocalBuilder.GetMethodBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Emit.LocalBuilder的用法示例。


在下文中一共展示了LocalBuilder.GetMethodBuilder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Emit

        public virtual void Emit(OpCode opcode, LocalBuilder local)
        {
            // Puts the opcode onto the IL stream followed by the information for local variable local.

            if (local == null)
            {
                throw new ArgumentNullException("local");
            }
            Contract.EndContractBlock();
            int tempVal = local.GetLocalIndex();
            if (local.GetMethodBuilder() != m_methodBuilder)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_UnmatchedMethodForLocal"), "local");
            }
            // If the instruction is a ldloc, ldloca a stloc, morph it to the optimal form.
            if (opcode.Equals(OpCodes.Ldloc))
            {
                switch(tempVal)
                {
                    case 0:
                        opcode = OpCodes.Ldloc_0;
                        break;
                    case 1:
                        opcode = OpCodes.Ldloc_1;
                        break;
                    case 2:
                        opcode = OpCodes.Ldloc_2;
                        break;
                    case 3:
                        opcode = OpCodes.Ldloc_3;
                        break;
                    default:
                        if (tempVal <= 255)
                            opcode = OpCodes.Ldloc_S;
                        break;
                }
            }
            else if (opcode.Equals(OpCodes.Stloc))
            {
                switch(tempVal)
                {
                    case 0:
                        opcode = OpCodes.Stloc_0;
                        break;
                    case 1:
                        opcode = OpCodes.Stloc_1;
                        break;
                    case 2:
                        opcode = OpCodes.Stloc_2;
                        break;
                    case 3:
                        opcode = OpCodes.Stloc_3;
                        break;
                    default:
                        if (tempVal <= 255)
                            opcode = OpCodes.Stloc_S;
                        break;
                }
            }
            else if (opcode.Equals(OpCodes.Ldloca))
            {
                if (tempVal <= 255)
                    opcode = OpCodes.Ldloca_S;
            }

            EnsureCapacity(7);
            InternalEmit(opcode);
             
            if (opcode.OperandType == OperandType.InlineNone)
                return;
            else if (!OpCodes.TakesSingleByteArgument(opcode))
            {
                m_ILStream[m_length++]=(byte) tempVal;
                m_ILStream[m_length++]=(byte) (tempVal>>8);
            }
            else
            {
                //Handle stloc_1, ldloc_1
                if (tempVal > Byte.MaxValue)
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadInstructionOrIndexOutOfBound"));
                }
                m_ILStream[m_length++]=(byte)tempVal;
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:85,代码来源:ilgenerator.cs

示例2: Emit

        public virtual void Emit(OpCode opcode, LocalBuilder local)
        {
            if (local == null)
            {
                throw new ArgumentNullException("local");
            }
            int localIndex = local.GetLocalIndex();
            if (local.GetMethodBuilder() != this.m_methodBuilder)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_UnmatchedMethodForLocal"), "local");
            }
            if (opcode.Equals(OpCodes.Ldloc))
            {
                switch (localIndex)
                {
                    case 0:
                        opcode = OpCodes.Ldloc_0;
                        goto Label_0123;

                    case 1:
                        opcode = OpCodes.Ldloc_1;
                        goto Label_0123;

                    case 2:
                        opcode = OpCodes.Ldloc_2;
                        goto Label_0123;

                    case 3:
                        opcode = OpCodes.Ldloc_3;
                        goto Label_0123;
                }
                if (localIndex <= 0xff)
                {
                    opcode = OpCodes.Ldloc_S;
                }
            }
            else if (opcode.Equals(OpCodes.Stloc))
            {
                switch (localIndex)
                {
                    case 0:
                        opcode = OpCodes.Stloc_0;
                        goto Label_0123;

                    case 1:
                        opcode = OpCodes.Stloc_1;
                        goto Label_0123;

                    case 2:
                        opcode = OpCodes.Stloc_2;
                        goto Label_0123;

                    case 3:
                        opcode = OpCodes.Stloc_3;
                        goto Label_0123;
                }
                if (localIndex <= 0xff)
                {
                    opcode = OpCodes.Stloc_S;
                }
            }
            else if (opcode.Equals(OpCodes.Ldloca) && (localIndex <= 0xff))
            {
                opcode = OpCodes.Ldloca_S;
            }
        Label_0123:
            this.EnsureCapacity(7);
            this.InternalEmit(opcode);
            if (opcode.OperandType != OperandType.InlineNone)
            {
                if (!OpCodes.TakesSingleByteArgument(opcode))
                {
                    this.m_ILStream[this.m_length++] = (byte) localIndex;
                    this.m_ILStream[this.m_length++] = (byte) (localIndex >> 8);
                }
                else
                {
                    if (localIndex > 0xff)
                    {
                        throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadInstructionOrIndexOutOfBound"));
                    }
                    this.m_ILStream[this.m_length++] = (byte) localIndex;
                }
            }
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:85,代码来源:ILGenerator.cs


注:本文中的System.Reflection.Emit.LocalBuilder.GetMethodBuilder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。