/// <inheritdoc /> public int GetVariableIndex(object operand) { return(operand switch { CilLocalVariable localVariable => localVariable.Index, byte raw => raw, ushort raw => raw, _ => throw new NotSupportedException("Unsupported variable operand.") });
/// <inheritdoc /> public int GetVariableIndex(object operand) { return(operand switch { CilLocalVariable localVariable => localVariable.Index, byte raw => raw, ushort raw => raw, _ => _diagnosticBag.RegisterExceptionAndReturnDefault <int>( new NotSupportedException($"Invalid or unsupported variable operand ({operand.SafeToString()}).")) });
/// <summary> /// Verifies and inserts a instruction into the collection that references a local variable. /// </summary> /// <param name="index">The zero-based index at which the instruction should be inserted at.</param> /// <param name="code">The opcode.</param> /// <param name="variable">The referenced variable.</param> /// <returns>The created instruction.</returns> /// <exception cref="InvalidCilInstructionException"> /// Occurs when the provided operation is not an opcode referencing a variable. /// </exception> /// <exception cref="ArgumentNullException"> /// Occurs when <paramref name="variable"/> is null. /// </exception> public CilInstruction Insert(int index, CilOpCode code, CilLocalVariable variable) { if (code.OperandType != CilOperandType.InlineVar && code.OperandType != CilOperandType.ShortInlineVar) { throw new InvalidCilInstructionException(code); } if (variable is null) { throw new ArgumentNullException(nameof(variable)); } return(InsertAndReturn(index, code, variable)); }
public CilInstruction Add(CilOpCode code, CilLocalVariable variable) => Insert(Count, code, variable);