C# Class Microsoft.Cci.MutableCodeModel.MethodBodyNormalizer

A class providing functionality to rewrite high level constructs such as anonymous delegates and yield statements into helper classes and methods, thus making it easier to generate IL from the CodeModel.
显示文件 Open project: visualmutator/visualmutator Class Usage Examples

Public Methods

Method Description
GetNormalizedSourceMethodBodyFor ( IMethodDefinition method, IBlockStatement body ) : SourceMethodBody

Given a method definition and a block of statements that represents the Block property of the body of the method, returns a SourceMethod with a body that no longer has any yield statements or anonymous delegate expressions. The given block of statements is mutated in place.

MethodBodyNormalizer ( IMetadataHost host, ISourceLocationProvider sourceLocationProvider ) : Microsoft.Cci.MutableCodeModel

A class providing functionality to rewrite high level constructs such as anonymous delegates and yield statements into helper classes and methods, thus making it easier to generate IL from the CodeModel.

Private Methods

Method Description
GetNormalizedIteratorBody ( IBlockStatement body, IMethodDefinition method, List privateHelperTypes ) : BlockStatement

Given the body of an iterator method body, this method try to compile its body. Specifically, this method: 1) creates a closure class that implements: IEnumerator, generic and nongeneric versions, IEnumerable, generic and nongeneric versions, and IDisposable. The generic versions of IEnumerator and IEnumerator is instantiated by a type T that is used to instantiate the return type of the iterator method. The members of the closure class include: 1.1) fields corresponding to every parameter and local variables. 1.2) fields that manages the state machine: __current and __state, and a currentThreadId field. 1.3) a constructor that takes one int argument. 1.4) methods that are required by the interfaces of the closure class: MoveNext, Reset, GetEnumerator, Current getter, and DisposeMethod. (GetEnumerator is needed only if the iterator's type is IEnumerable and not IEnumerator.) 2) creates the new body of the iterator method: which returns a local variable that holds a new object of the closure class, with the fields of the closure class that correspond to the parameters (including the self parameter if applicable) initialized. 3) transforms the body, which should now not contain any annonymous delegates, into the body of the MoveNext method of the closure class. This includes: 3.1) every local/parameter reference -> this.field reference 3.2) every yield return or yield break -> assignment to current and return true or false, respectively. 3.3) a switch statement for the state machine, with state values corresponds to each yield return/yield break 3.4) a try block if an iterator is created in the body. 4) If the iterator method has a type parameter, so will the closure class. Make sure in the closure class only the right type parameter is referenced.

Method Details

GetNormalizedSourceMethodBodyFor() public method

Given a method definition and a block of statements that represents the Block property of the body of the method, returns a SourceMethod with a body that no longer has any yield statements or anonymous delegate expressions. The given block of statements is mutated in place.
public GetNormalizedSourceMethodBodyFor ( IMethodDefinition method, IBlockStatement body ) : SourceMethodBody
method IMethodDefinition
body IBlockStatement
return SourceMethodBody

MethodBodyNormalizer() public method

A class providing functionality to rewrite high level constructs such as anonymous delegates and yield statements into helper classes and methods, thus making it easier to generate IL from the CodeModel.
public MethodBodyNormalizer ( IMetadataHost host, ISourceLocationProvider sourceLocationProvider ) : Microsoft.Cci.MutableCodeModel
host IMetadataHost An object representing the application that is hosting the converter. It is used to obtain access to some global /// objects and services such as the shared name table and the table for interning references.
sourceLocationProvider ISourceLocationProvider An object that can map the ILocation objects found in a block of statements to IPrimarySourceLocation objects. May be null.
return Microsoft.Cci.MutableCodeModel