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


C# IMethodBody类代码示例

本文整理汇总了C#中IMethodBody的典型用法代码示例。如果您正苦于以下问题:C# IMethodBody类的具体用法?C# IMethodBody怎么用?C# IMethodBody使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: DebugReplacementGeneratorForBody

    public override ILGenerator DebugReplacementGeneratorForBody(IMethodBody methodBody) {
      string warningText = "Attempt to execute garbage collected method: " + methodBody.MethodDefinition.ToString();

      var generator = new ILGenerator(host, methodBody.MethodDefinition);

      // emit console warning
      generator.Emit(OperationCode.Ldstr, warningText);
      generator.Emit(OperationCode.Call, this.consoleWriteLine);

      //emit stack trace

      // pushes stack trace on stack
      generator.Emit(OperationCode.Call, this.environmentGetStackTrace);
      // consumes stack trace
      generator.Emit(OperationCode.Call, this.consoleWriteLine);

      // may want to flush output?

      // emit exit

      generator.Emit(OperationCode.Ldc_I4_M1);
      generator.Emit(OperationCode.Call, this.environmentExit);

      // Makes the verifier happy; this should never be reached

      AppendEmitExceptionThrow(generator);

      return generator;
    }
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:29,代码来源:Sweep.cs

示例2: Traverse

    public override void Traverse(IMethodBody methodBody) {
      sourceEmitterOutput.WriteLine("");
      this.sourceEmitterOutput.WriteLine(MemberHelper.GetMethodSignature(methodBody.MethodDefinition,
        NameFormattingOptions.Signature|NameFormattingOptions.ReturnType|NameFormattingOptions.ParameterModifiers|NameFormattingOptions.ParameterName));
      sourceEmitterOutput.WriteLine("");
      if (this.pdbReader != null)
        PrintScopes(methodBody);
      else
        PrintLocals(methodBody.LocalVariables);

      this.cdfg = ControlAndDataFlowGraph<AiBasicBlock<Instruction>, Instruction>.GetControlAndDataFlowGraphFor(host, methodBody, this.pdbReader);
      this.cfgQueries = new ControlGraphQueries<AiBasicBlock<Instruction>, Instruction>(this.cdfg);
      SingleAssigner<AiBasicBlock<Instruction>, Instruction>.GetInSingleAssignmentForm(host.NameTable, this.cdfg, this.cfgQueries, this.pdbReader);
      this.valueMappings = new ValueMappings<Instruction>(this.host.PlatformType, new Z3Wrapper.Wrapper(host.PlatformType));
      AbstractInterpreter<AiBasicBlock<Instruction>, Instruction>.InterpretUsingAbstractValues(this.cdfg, this.cfgQueries, this.valueMappings);

      var numberOfBlocks = this.cdfg.BlockFor.Count;

      foreach (var block in this.cdfg.AllBlocks) {
        this.PrintBlock(block);
      }

      sourceEmitterOutput.WriteLine("**************************************************************");
      sourceEmitterOutput.WriteLine();
    }
开发者ID:RUB-SysSec,项目名称:Probfuscator,代码行数:25,代码来源:SourceEmitter.cs

示例3: MinimalReplacementGeneratorForBody

    public virtual ILGenerator MinimalReplacementGeneratorForBody(IMethodBody methodBody) {
      var generator = new ILGenerator(host, methodBody.MethodDefinition);

      AppendEmitExceptionThrow(generator);

      return generator;
    }
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:7,代码来源:Sweep.cs

示例4: SynthesizedMethodBodyDecorator

 public SynthesizedMethodBodyDecorator(IMethodBody methodBody, IList<IType> locals, byte[] customBody)
     : this(methodBody)
 {
     this.customBody = customBody;
     var index = 0;
     this.locals = locals.Select(t => new SynthesizedLocalVariable(index++, t)).ToList();
 }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:7,代码来源:SynthesizedMethodBodyDecorator.cs

示例5: VerifyResult

 protected void VerifyResult(IMethodBody mb)
 {
     var s_actual = mb.StringJoin(Environment.NewLine);
     s_actual = Regex.Replace(s_actual, @"Snippets.<>c__DisplayClass.*::", "<Closure>::");
     s_actual = Regex.Replace(s_actual, @"CS\$<>8__locals.*\)", "<Closure>)");
     s_actual = Regex.Replace(s_actual, @"0x[a-fA-f0-9]{8}", "<MetadataToken>");
     VerifyResult(s_actual);
 }
开发者ID:xeno-by,项目名称:truesight-lite,代码行数:8,代码来源:Tests.Boilerplate.cs

示例6: Rewrite

        /// <summary>
        /// Rewrites the target method body. This class will only insert a single call into the beginning of the
        /// method that writes it's signature using the <see cref="TestUtil"/> class.
        /// </summary>
        /// <param name="methodBody">
        /// The method body to rewrite.
        /// </param>
        /// <returns>
        /// The rewritten method body.
        /// </returns>
        public override IMethodBody Rewrite(IMethodBody methodBody)
        {
            if (this.rewriter == null)
            {
                throw new InvalidOperationException("Unable to rewrite method body. Call Rewrite(IInstrumentationTarget target) instead of calling this directly.");
            }

            return this.rewriter.Rewrite(methodBody);
        }
开发者ID:jduv,项目名称:WinBert,代码行数:19,代码来源:DynamicCallGraphInstrumentor.cs

示例7: SerializeMethodDebugInfo

        public byte[] SerializeMethodDebugInfo(EmitContext context, IMethodBody methodBody, uint methodToken, bool isEncDelta, bool suppressNewCustomDebugInfo, out bool emitExternNamespaces)
        {
            emitExternNamespaces = false;

            // CONSIDER: this may not be the same "first" method as in Dev10, but
            // it shouldn't matter since all methods will still forward to a method
            // containing the appropriate information.
            if (_methodBodyWithModuleInfo == null) //UNDONE: || edit-and-continue
            {
                // This module level information could go on every method (and does in
                // the edit-and-continue case), but - as an optimization - we'll just
                // put it on the first method we happen to encounter and then put a
                // reference to the first method's token in every other method (so they
                // can find the information).
                if (context.Module.GetAssemblyReferenceAliases(context).Any())
                {
                    _methodTokenWithModuleInfo = methodToken;
                    _methodBodyWithModuleInfo = methodBody;
                    emitExternNamespaces = true;
                }
            }

            var customDebugInfo = ArrayBuilder<MemoryStream>.GetInstance();

            SerializeIteratorClassMetadata(methodBody, customDebugInfo);

            // NOTE: This is an attempt to match Dev10's apparent behavior.  For iterator methods (i.e. the method
            // that appears in source, not the synthesized ones), Dev10 only emits the ForwardIterator and IteratorLocal
            // custom debug info (e.g. there will be no information about the usings that were in scope).
            // NOTE: There seems to be an unusual behavior in ISymUnmanagedWriter where, if all the methods in a type are
            // iterator methods, no custom debug info is emitted for any method.  Adding a single non-iterator
            // method causes the custom debug info to be produced for all methods (including the iterator methods).
            // Since we are making the same ISymUnmanagedWriter calls as Dev10, we see the same behavior (i.e. this
            // is not a regression).
            if (methodBody.StateMachineTypeName == null)
            {
                SerializeNamespaceScopeMetadata(context, methodBody, customDebugInfo);
                SerializeStateMachineLocalScopes(methodBody, customDebugInfo);
            }

            if (!suppressNewCustomDebugInfo)
            {
                SerializeDynamicLocalInfo(methodBody, customDebugInfo);

                // delta doesn't need this information - we use information recorded by previous generation emit
                if (!isEncDelta)
                {
                    var encMethodInfo = MetadataWriter.GetEncMethodDebugInfo(methodBody);
                    SerializeCustomDebugInformation(encMethodInfo, customDebugInfo);
                }
            }

            byte[] result = SerializeCustomDebugMetadata(customDebugInfo);
            customDebugInfo.Free();
            return result;
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:56,代码来源:CustomDebugInfoWriter.cs

示例8: SynthesizedMethodDecorator

 public SynthesizedMethodDecorator(
     IMethod method,
     IMethodBody methodBody,
     IEnumerable<IParameter> parameters,
     IModule module) : this(method)
 {
     this.methodBody = methodBody;
     this.module = module;
     this.parameters = parameters;
 }
开发者ID:afrog33k,项目名称:csnative,代码行数:10,代码来源:SynthesizedMethodDecorator.cs

示例9: Rewrite

    public override IMethodBody Rewrite(IMethodBody methodBody) {
      this.cdfg = ControlAndDataFlowGraph<BasicBlock<Instruction>, Instruction>.GetControlAndDataFlowGraphFor(this.host, methodBody);
      this.ilGenerator = new ILGenerator(host, methodBody.MethodDefinition);

      var numberOfBlocks = this.cdfg.BlockFor.Count;
      this.labelFor = new Hashtable<ILGeneratorLabel>(numberOfBlocks);
      this.counterFieldsForCurrentMethod = new NestedTypeDefinition() {
        BaseClasses = new List<ITypeReference>(1) { this.host.PlatformType.SystemObject },
        ContainingTypeDefinition = methodBody.MethodDefinition.ContainingTypeDefinition,
        Fields = new List<IFieldDefinition>((int)numberOfBlocks*2),
        Methods = new List<IMethodDefinition>(1),
        InternFactory = this.host.InternFactory,
        IsBeforeFieldInit = true,
        IsClass = true,
        IsSealed = true,
        IsAbstract = true,
        Name = this.host.NameTable.GetNameFor(methodBody.MethodDefinition.Name+"_Counters"+methodBody.MethodDefinition.InternedKey),
        Visibility = TypeMemberVisibility.Assembly,
      };
      this.fieldOffsets = new List<uint>((int)numberOfBlocks*2);

      foreach (var exceptionInfo in methodBody.OperationExceptionInformation) {
        this.ilGenerator.AddExceptionHandlerInformation(exceptionInfo.HandlerKind, exceptionInfo.ExceptionType,
          this.GetLabelFor(exceptionInfo.TryStartOffset), this.GetLabelFor(exceptionInfo.TryEndOffset),
          this.GetLabelFor(exceptionInfo.HandlerStartOffset), this.GetLabelFor(exceptionInfo.HandlerEndOffset),
          exceptionInfo.HandlerKind == HandlerKind.Filter ? this.GetLabelFor(exceptionInfo.FilterDecisionStartOffset) : null);
      }

      if (this.pdbReader == null) {
        foreach (var localDef in methodBody.LocalVariables)
          this.ilGenerator.AddVariableToCurrentScope(localDef);
      } else {
        foreach (var ns in this.pdbReader.GetNamespaceScopes(methodBody)) {
          foreach (var uns in ns.UsedNamespaces)
            this.ilGenerator.UseNamespace(uns.NamespaceName.Value);
        }
        this.scopeEnumerator = this.pdbReader.GetLocalScopes(methodBody).GetEnumerator();
        this.scopeEnumeratorIsValid = this.scopeEnumerator.MoveNext();
      }

      foreach (var block in this.cdfg.AllBlocks)
        this.InstrumentBlock(block);

      while (this.scopeStack.Count > 0) {
        this.ilGenerator.EndScope();
        this.scopeStack.Pop();
      }

      this.ilGenerator.AdjustBranchSizesToBestFit();

      this.InjectMethodToDumpCounters();

      return new ILGeneratorMethodBody(this.ilGenerator, methodBody.LocalsAreZeroed, (ushort)(methodBody.MaxStack+2), methodBody.MethodDefinition,
        methodBody.LocalVariables, IteratorHelper.GetSingletonEnumerable((ITypeDefinition)this.counterFieldsForCurrentMethod));
    }
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:55,代码来源:AddInstrumentation.cs

示例10: DoBuildControlFlowGraph

        public static ControlFlowGraph DoBuildControlFlowGraph(IMethodBody cil, Symbols symbols)
        {
            ReadOnlyDictionary<ControlFlowBlock, ReadOnlyCollection<IILOp>> blocks2parts;
            var cfg = CreateCarcass.DoCreateCarcass(cil, out blocks2parts);
            foreach (var cfb in blocks2parts.Keys)
            {
                InitialDecompilation.DoPrimaryDecompilation(cfb, blocks2parts[cfb], symbols);
            }

            return cfg;
        }
开发者ID:xeno-by,项目名称:truesight-lite,代码行数:11,代码来源:BuildControlFlowGraph.cs

示例11: SerializeMethodDynamicAnalysisData

        internal void SerializeMethodDynamicAnalysisData(IMethodBody bodyOpt)
        {
            var data = bodyOpt?.DynamicAnalysisData;

            if (data == null)
            {
                _methodTable.Add(default(MethodRow));
                return;
            }

            BlobHandle spanBlob = SerializeSpans(data.Spans, _documentIndex);
            _methodTable.Add(new MethodRow { Spans = spanBlob });
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:13,代码来源:MetadataWriter.DynamicAnalysis.cs

示例12: Rewrite

            public override IMethodBody Rewrite(IMethodBody body)
            {
                var method = body.MethodDefinition;
                _log.Info("Rewriting IMethodBody of: " + method + " Pass: " + MutationTarget.PassInfo);
     
                var newBody = new SourceMethodBody(Host)
                {
                    MethodDefinition = method,
                    LocalsAreZeroed = true
                };
                var block = new BlockStatement();
                newBody.Block = block;

                var replacement = method.ContainingTypeDefinition.Methods.Single(m => m.ToString() == MutationTarget.PassInfo);
                var methodCall = new MethodCall
                    {
                        MethodToCall = replacement,
                        Type = replacement.Type,
                        ThisArgument = new ThisReference() {Type = method.ContainingTypeDefinition}
                    };
                foreach (var param in replacement.Parameters)
                {
                    methodCall.Arguments.Add(new BoundExpression()
                        {
                            Definition = method.Parameters
                                .First(p =>
                                    ((INamedTypeReference)p.Type).Name.Value ==
                                    ((INamedTypeReference)param.Type).Name.Value)
                        });
                    //  methodCall.Arguments.Add(method.Parameters.First(p => new ));
                }

                if (replacement.Type == Host.PlatformType.SystemVoid)
                {
                    block.Statements.Add(new ExpressionStatement
                    {
                        Expression = methodCall
                    });
                    block.Statements.Add(new ReturnStatement());
                }
                else
                {
                    block.Statements.Add(new ReturnStatement
                    {
                        Expression = methodCall
                    });
                   
                }
        
                return newBody;
            }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:51,代码来源:OMR_OverloadingMethodContentsChange.cs

示例13: Visit

            public override void Visit(IMethodBody body)
            {
                var method = body.MethodDefinition;
                _log.Info("Visiting IMethodBody of: " + method);

                var methods = FindCandidateMethods(method);
                var compatibileMethods = methods.Where(m => m.Parameters
                    .All(p => method.Parameters.Any(p2 => p2.Type == p.Type))).ToList();

                if(compatibileMethods.Count != 0)
                {
              
                    MarkMutationTarget(body, compatibileMethods.First().ToString().InList());
                }
  
            }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:16,代码来源:OMR_OverloadingMethodContentsChange.cs

示例14: Traverse

        public override void Traverse(IMethodBody methodBody)
        {
            var moduleInfo =  _module.ModulesInfo.Single();
            var smb =  new Microsoft.Cci.ILToCodeModel.SourceMethodBody(methodBody, _module.Host, moduleInfo.PdbReader, moduleInfo.LocalScopeProvider, DecompilerOptions.None);
           
            _visitor.MethodBodyEnter(smb);
            Traverse(smb);
            var descriptor = _visitor.MethodBodyExit(smb);
            var targetsDescriptors = _visitor.MutationTargets.Select(t => t.ProcessingContext.Descriptor).ToList();

          //  _log.Debug("Returned :"+ descriptor+" comparing with mutaion targets: "+ targetsDescriptors.MakeString());
            if(targetsDescriptors.Any(a => a.IsContainedIn(descriptor)))
            {
                _log.Debug("Adding method body :" + descriptor );
                _methodBodies.Add(methodBody, smb);
            }
        }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:17,代码来源:VisualCodeTraverser.cs

示例15: SynthesizedSingleDimArrayIListGetEnumeratorMethod

        /// <summary>
        /// </summary>
        /// <param name="type">
        /// </param>
        /// <param name="typeResolver">
        /// </param>
        public SynthesizedSingleDimArrayIListGetEnumeratorMethod(IType arrayType, ITypeResolver typeResolver)
            : base("GetEnumerator", arrayType, typeResolver.System.System_Collections_Generic_IEnumerator_T.Construct(arrayType.GetElementType()))
        {
            var codeList = new IlCodeBuilder();
            codeList.LoadArgument(0);
            codeList.Add(Code.Newobj, 1);
            codeList.Add(Code.Newobj, 2);
            codeList.Add(Code.Ret);

            var locals = new List<IType>();

            this._methodBody =
                new SynthesizedMethodBodyDecorator(
                    null,
                    locals,
                    codeList.GetCode());

            this._parameters = new List<IParameter>();

            this._tokenResolutions = new List<object>();

            var arraySegmentType = typeResolver.System.System_ArraySegment_T1.Construct(arrayType.GetElementType());
            this._tokenResolutions.Add(
                IlReader.Constructors(arraySegmentType, typeResolver).First(c => c.GetParameters().Count() == 1));
            this._tokenResolutions.Add(
                IlReader.Constructors(arraySegmentType.GetNestedTypes().First(), typeResolver).First(c => c.GetParameters().Count() == 1));
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:33,代码来源:SynthesizedSingleDimArrayIListGetEnumeratorMethod.cs


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