本文整理汇总了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();
//.........这里部分代码省略.........