當前位置: 首頁>>代碼示例>>C#>>正文


C# Instruction.ToString方法代碼示例

本文整理匯總了C#中Mono.Cecil.Cil.Instruction.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# Instruction.ToString方法的具體用法?C# Instruction.ToString怎麽用?C# Instruction.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.Cil.Instruction的用法示例。


在下文中一共展示了Instruction.ToString方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: InstructionToString

 private string InstructionToString(Instruction i)
 {
     return i.ToString().Split(new[] {": "}, 2, StringSplitOptions.None)[1];
 }
開發者ID:provegard,項目名稱:testness,代碼行數:4,代碼來源:TestHelperTest.cs

示例2: Instrument

        private static void Instrument (
                                      AssemblyDefinition assembly,
                                      TypeDefinition type,
                                       Instruction instruction,
                                       MethodReference countReference,
                                       MethodDefinition method,
                                       ILProcessor worker,
                                       string lastLine,
                                       InstrumentConfig config,
                                       TextWriter writer,
                                       ref int instrumentIndex)
        {
            //if the previous instruction is a Prefix instruction then this instruction MUST go with it.
            //we cannot put an instruction between the two.
            if (instruction.Previous != null && instruction.Previous.OpCode.OpCodeType == OpCodeType.Prefix)
                return;

            if (config.HasOffset (method.FullName, instruction.Offset))
                return;

            if (lastLine != null && config.HasLine (method.FullName, lastLine)) {
                return;
            }

            var lineNumStart = -1;
            var lineNumEnd = -1;
            if (instruction.SequencePoint != null) {
                lineNumStart = instruction.SequencePoint.StartLine;
                lineNumEnd = instruction.SequencePoint.EndLine;
            }

            var parentTypeRef = type;
            while (parentTypeRef.DeclaringType != null)
                parentTypeRef = parentTypeRef.DeclaringType;

            var line = string.Join ("\t",
                                   assembly.Name,  //0
                                   parentTypeRef.FullName,//1
                                   method.FullName, //2 
                                   lineNumStart, //3
                                   lineNumEnd, //4 
                                   instruction.Offset, //5
                                   instruction.ToString ().Replace ("\n", " "), //6
                                   instruction.SequencePoint?.Document.Url); //7

   
            writer.WriteLine (line);

            var pathParamLoadInstruction = worker.Create (OpCodes.Ldstr, config.HitsPathPrefix);
            var lineParamLoadInstruction = worker.Create (OpCodes.Ldc_I4, instrumentIndex);
            var registerInstruction = worker.Create (OpCodes.Call, countReference);

            //inserting method before instruction  because after will not happen after a method Ret instruction
            worker.InsertBefore (instruction, pathParamLoadInstruction);
            worker.InsertAfter (pathParamLoadInstruction, lineParamLoadInstruction);
            worker.InsertAfter (lineParamLoadInstruction, registerInstruction);

            ++instrumentIndex;

            //change try/finally etc to point to our first instruction if they referenced the one we inserted before
            foreach (var handler in method.Body.ExceptionHandlers) {
                if (handler.FilterStart == instruction)
                    handler.FilterStart = pathParamLoadInstruction;

                if (handler.TryStart == instruction)
                    handler.TryStart = pathParamLoadInstruction;
                if (handler.TryEnd == instruction)
                    handler.TryEnd = pathParamLoadInstruction;

                if (handler.HandlerStart == instruction)
                    handler.HandlerStart = pathParamLoadInstruction;
                if (handler.HandlerEnd == instruction)
                    handler.HandlerEnd = pathParamLoadInstruction;
            }

            //change instructions with a target instruction if they referenced the one we inserted before to be our first instruction
            foreach (var iteratedInstruction in method.Body.Instructions) {
                var operand = iteratedInstruction.Operand;
                if (operand == instruction) {
                    iteratedInstruction.Operand = pathParamLoadInstruction;
                    continue;
                }

                if (!(operand is Instruction []))
                    continue;

                var operands = (Instruction [])operand;
                for (var i = 0; i < operands.Length; ++i) {
                    if (operands [i] == instruction)
                        operands [i] = pathParamLoadInstruction;
                }
            }
        }
開發者ID:maciejczechowski,項目名稱:SharpCover,代碼行數:93,代碼來源:Program.cs

示例3: CreateInstructionRecord

 /// <summary>
 /// Create an Instruction record in the database
 /// </summary>
 /// <param name="command">Command factory object</param>
 /// <param name="instruction">Instruction</param>
 private void CreateInstructionRecord(CommandFactory command, Instruction instruction)
 {
     command.Insert<InstructionField>(
         command.GetLastId<AssemblyField>(),
         command.GetLastId<ModuleField>(),
         command.GetLastId<TypeField>(),
         command.GetLastId<MethodField>(),
         instruction.ToString()
     );
 }
開發者ID:rshekhtm,項目名稱:OmniQuery,代碼行數:15,代碼來源:CodeAnalysis.cs


注:本文中的Mono.Cecil.Cil.Instruction.ToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。