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


C# Method.ClearBody方法代码示例

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


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

示例1: ExtractContractsForMethod

        private void ExtractContractsForMethod(Method method, object dummy)
        {
            Contract.Requires(method != null);

            RequiresList preconditions = null;
            EnsuresList postconditions = null;
            RequiresList validations = null;
            EnsuresList modelPostconditions = null;

            //Console.WriteLine("Extracting contract for method {0}", method.FullName);

            // set its contract so pure is properly handled.
            var methodContract = method.Contract = new MethodContract(method);

            try
            {
                if (method.IsAbstract /* && contractClass == null */)
                {
                    // Abstract methods cannot have a body, so nothing to extract
                    return;
                }

                TypeNode /*?*/ closure = null;
                bool possiblyAsync;
                if (IsIteratorOrAsyncMethodCandidate(method, out possiblyAsync))
                {
                    closure = FindClosureClass(method);
                    if (closure != null)
                    {
                        this.ProcessClosureClass(method, closure, possiblyAsync);
                        return;
                    }
                }

                if (method.Body == null || method.Body.Statements == null)
                    return;

                // Find first source context, use it if no better one is found on errors

                // if (method.Body != null && method.Body.Statements != null)
                {
                    if (this.verbose)
                    {
                        Console.WriteLine(method.FullName);
                    }

                    bool found = false;
                    for (int i = 0, n = method.Body.Statements.Count; i < n && !found; i++)
                    {
                        Block b = method.Body.Statements[i] as Block;
                        if (b != null)
                        {
                            for (int j2 = 0, m = b.Statements == null ? 0 : b.Statements.Count; j2 < m; j2++)
                            {
                                Contract.Assert(m == b.Statements.Count, "loop invariant not inferred");

                                Statement s = b.Statements[j2];
                                if (s != null)
                                {
                                    SourceContext sctx = s.SourceContext;
                                    if (sctx.IsValid)
                                    {
                                        found = true;
                                        // s.SourceContext = new SourceContext(); // wipe out the source context because this statement will no longer be the first one in the method body if there are any contract calls
                                        this.currentMethodSourceContext = sctx;
                                        if (this.verbose)
                                        {
                                            Console.WriteLine("block {0}, statement {1}: ({2},{3})", i, j2, sctx.StartLine, sctx.StartColumn);
                                        }

                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                Block contractInitializerBlock = new Block(new StatementList());
                Block postPreamble = null;

                HelperMethods.StackDepthTracker dupStackTracker = new HelperMethods.StackDepthTracker();

                var contractLocalAliasingThis = HelperMethods.ExtractPreamble(method, this.contractNodes,
                    contractInitializerBlock, out postPreamble, ref dupStackTracker, this.isVB);

                bool saveErrorFound = this.errorFound;
                this.errorFound = false;

                // Extract pre- and postconditions

                if (method.Body != null && method.Body.Statements != null)
                {
                    this.CheapAndDirty(method, ref preconditions, ref postconditions, ref validations,
                        ref modelPostconditions, contractInitializerBlock, ref dupStackTracker);

                    if (this.errorFound)
                    {
                        method.ClearBody();

//.........这里部分代码省略.........
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:101,代码来源:ExtractorVisitor.cs


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