Beispiel #1
0
        /// <summary>
        /// Creates a copy of the instruction.
        /// </summary>
        /// <param name="original"></param>
        /// <returns></returns>
        public static Instruction CopyInstruction(Instruction original)
        {
            if (original.Operand is byte)
            {
                return(Instruction.Create(original.OpCode, (byte)original.Operand));
            }
            else if (original.Operand is CallSite)
            {
                return(Instruction.Create(original.OpCode, original.Operand as CallSite));
            }
            else if (original.Operand is double)
            {
                return(Instruction.Create(original.OpCode, (double)original.Operand));
            }
            else if (original.Operand is FieldReference)
            {
                return(Instruction.Create(original.OpCode, original.Operand as FieldReference));
            }
            else if (original.Operand is float)
            {
                return(Instruction.Create(original.OpCode, (float)original.Operand));
            }
            else if (original.Operand is Instruction)
            {
                return(Instruction.Create(original.OpCode, IL.CopyInstruction(original.Operand as Instruction)));
            }
            else if (original.Operand is Instruction[])
            {
                Instruction[] set = new Instruction[(original.Operand as Instruction[]).Length];

                for (int i = 0; i < set.Length; i++)
                {
                    set[i] = IL.CopyInstruction((original.Operand as Instruction[])[i]);
                }

                return(Instruction.Create(original.OpCode, set));
            }
            else if (original.Operand is int)
            {
                return(Instruction.Create(original.OpCode, (int)original.Operand));
            }
            else if (original.Operand is long)
            {
                return(Instruction.Create(original.OpCode, (long)original.Operand));
            }
            else if (original.Operand is MethodReference)
            {
                return(Instruction.Create(original.OpCode, original.Operand as MethodReference));
            }
            else if (original.Operand is ParameterDefinition)
            {
                return(Instruction.Create(original.OpCode, original.Operand as ParameterDefinition));
            }
            else if (original.Operand is sbyte)
            {
                return(Instruction.Create(original.OpCode, (sbyte)original.Operand));
            }
            else if (original.Operand is String)
            {
                return(Instruction.Create(original.OpCode, original.Operand as String));
            }
            else if (original.Operand is TypeReference)
            {
                return(Instruction.Create(original.OpCode, original.Operand as TypeReference));
            }
            else if (original.Operand is VariableDefinition)
            {
                return(Instruction.Create(original.OpCode, original.Operand as VariableDefinition));
            }
            else
            {
                return(Instruction.Create(original.OpCode));
            }
        }