All pastes #640422 Raw Edit

Untitled

public text v1 · immutable
#640422 ·published 2007-07-31 11:51 UTC
rendered paste body
using System;
using System.Collections.Generic;

namespace Smokey
{    
    /// Contains all of the TypedInstructions in a method.
    public class TypedInstructions : IFormattable, IEnumerable<TypedInstruction>
    {        
        public TypedInstructions(MethodDefinition method)
        {
            m_method = method;
            
            m_instructions = new List<TypedInstruction>(method.Body.Instructions.Count);
            m_offsets = new Dictionary<int, TypedInstruction>(method.Body.Instructions.Count);
            
            foreach (Instruction untyped in method.Body.Instructions)
            {
                TypedInstruction instruction = DoGetTyped(untyped);
                
                m_instructions.Add(instruction);
                m_offsets.Add(untyped.Offset, instruction);
            }

            DoFixBranches();
        }
        
        public MethodDefinition Method {get {return m_method;}}
        
        public IEnumerator<TypedInstruction> GetEnumerator()
        {
            foreach (TypedInstruction instruction in m_instructions)
                yield return instruction;
        }
        
        public IEnumerator<T> Match<T>() where T: TypedInstruction
        {
            foreach (TypedInstruction instruction in m_instructions)
            {
                T instance = instruction as T;
                if (instance != null)
                    yield return instance;
            }
        }

        // snip
}

// error: [csc] TypedInstructions.cs(7,22): error CS0535: 
// `Smokey.TypedInstructions' does not implement interface member 
// `System.Collections.IEnumerable.GetEnumerator()'