@ -408,15 +408,21 @@ namespace ICSharpCode.CodeQualityAnalysis
@@ -408,15 +408,21 @@ namespace ICSharpCode.CodeQualityAnalysis
/// <param name="methodDefinition">A method definition with instructions</param>
/// <param name="instructions">A collection of instructions</param>
public void ReadInstructions ( Method method , MethodDefinition methodDefinition ,
Collection < Instruction > instructions )
Collection < Mono . Cecil . Cil . Instruction > instructions )
{
foreach ( Instruction instruction in instructions )
foreach ( var instruction in instructions )
{
var instr = ReadInstruction ( instruction ) ;
method . Instructions . Add ( new Instruction
{
DeclaringMethod = method ,
// Operand = instruction.Operand.ToString() // for now operand as string should be enough
} ) ;
var operand = ReadOperand ( instruction ) ;
if ( instr is MethodDefinition )
if ( operand is MethodDefinition )
{
var md = instr as MethodDefinition ;
var md = operand as MethodDefinition ;
var type = ( from n in method . Owner . Namespace . Module . Namespaces
from t in n . Types
where t . FullName = = FormatTypeName ( md . DeclaringType , true )
@ -432,9 +438,9 @@ namespace ICSharpCode.CodeQualityAnalysis
@@ -432,9 +438,9 @@ namespace ICSharpCode.CodeQualityAnalysis
method . MethodUses . Add ( findTargetMethod ) ;
}
if ( instr is FieldDefinition )
if ( operand is FieldDefinition )
{
var fd = instr as FieldDefinition ;
var fd = operand as FieldDefinition ;
var field = ( from f in method . Owner . Fields
where f . Name = = fd . Name
select f ) . SingleOrDefault ( ) ;
@ -445,6 +451,25 @@ namespace ICSharpCode.CodeQualityAnalysis
@@ -445,6 +451,25 @@ namespace ICSharpCode.CodeQualityAnalysis
}
}
/// <summary>
/// Reads an instruction operand by recursive calling until non-instruction
/// operand is found
/// </summary>
/// <param name="instruction">An instruction with operand</param>
/// <returns>An instruction operand</returns>
public object ReadOperand ( Mono . Cecil . Cil . Instruction instruction )
{
if ( instruction . Operand = = null )
return null ;
var nextInstruction = instruction . Operand as Mono . Cecil . Cil . Instruction ;
if ( nextInstruction ! = null )
return ReadOperand ( nextInstruction ) ;
return instruction . Operand ;
}
/// <summary>
/// Reads generic arguments from type and returns them as a set of types
/// </summary>
@ -473,25 +498,6 @@ namespace ICSharpCode.CodeQualityAnalysis
@@ -473,25 +498,6 @@ namespace ICSharpCode.CodeQualityAnalysis
return types ;
}
/// <summary>
/// Reads instruction operand by recursive calling until non-instruction
/// operand is found
/// </summary>
/// <param name="instruction">An instruction with operand</param>
/// <returns>An instruction operand</returns>
public object ReadInstruction ( Instruction instruction )
{
if ( instruction . Operand = = null )
return null ;
var nextInstruction = instruction . Operand as Instruction ;
if ( nextInstruction ! = null )
return ReadInstruction ( nextInstruction ) ;
return instruction . Operand ;
}
/// <summary>
/// Formats method name by adding parameters to it. If there are not any parameters
/// only empty brackers will be added.