Cilador.Clone.MultiplexedConstructor.TryGetIndexedVariableOperand C# (CSharp) Method

TryGetIndexedVariableOperand() private static method

If the instruction has a variable operand, retrieves it.
private static TryGetIndexedVariableOperand ( Instruction instruction, IEnumerable indexedVariables, Mono.Cecil.Cil.VariableDefinition &variable ) : bool
instruction Mono.Cecil.Cil.Instruction to look at
indexedVariables IEnumerable Collection of variables that are potentially referenced by the operand
variable Mono.Cecil.Cil.VariableDefinition to populate with the referenced indexed variable, if possible.
return bool
        private static bool TryGetIndexedVariableOperand(
            Instruction instruction,
            IEnumerable<VariableDefinition> indexedVariables,
            ref VariableDefinition variable)
        {
            int? variableIndex;
            if (!instruction.TryGetVariableIndex(out variableIndex)) { return false; }

            Contract.Assert(variableIndex.HasValue);
            variable = indexedVariables.FirstOrDefault(
                possibleInitializationVariable => possibleInitializationVariable.Index == variableIndex.Value);

            return variable != null;
        }

Usage Example

Example #1
0
 /// <summary>
 /// Finds a variable, if any, that is referenced by an instruction.
 /// </summary>
 /// <param name="instruction">Instruction that may reference a variable.</param>
 /// <param name="variable">When populated, this is the referenced variable.</param>
 /// <returns><c>true</c> if a variable referenced by the instruction was found, else <c>false</c>.</returns>
 private bool TryGetReferencedVariable(Instruction instruction, out VariableDefinition variable)
 {
     return
         (MultiplexedConstructor.TryGetVariableDefinitionOperand(instruction, out variable) ||
          MultiplexedConstructor.TryGetIndexedVariableOperand(instruction, this.Constructor.Body.Variables, ref variable));
 }