Microsoft.Cci.MutableCodeModel.IteratorClosureGenerator.CreateGetEnumeratorMethodNonGeneric C# (CSharp) Method

CreateGetEnumeratorMethodNonGeneric() private method

Create the non-generic version of GetEnumerator and add it to the member list of iterator closure class.
private CreateGetEnumeratorMethodNonGeneric ( IteratorClosureInformation iteratorClosure ) : void
iteratorClosure IteratorClosureInformation
return void
    private void CreateGetEnumeratorMethodNonGeneric(IteratorClosureInformation iteratorClosure) {
      // GetEnumerator non-generic version, which delegates to the generic version. 
      // Metadata
      MethodDefinition nongenericGetEnumerator = new MethodDefinition() {
        Attributes = new List<ICustomAttribute>(1),
        InternFactory = this.host.InternFactory,
        Name = this.host.NameTable.GetNameFor("System.Collections.IEnumerable.GetEnumerator")
      };
      nongenericGetEnumerator.Attributes.Add(
        new CustomAttribute() { Constructor = this.DebuggerHiddenCtor }
        );
      nongenericGetEnumerator.CallingConvention |= CallingConvention.HasThis;
      nongenericGetEnumerator.ContainingTypeDefinition = iteratorClosure.ClosureDefinition;
      nongenericGetEnumerator.Visibility = TypeMemberVisibility.Public;
      nongenericGetEnumerator.Type = iteratorClosure.NonGenericIEnumeratorInterface;
      nongenericGetEnumerator.IsVirtual = true;
      nongenericGetEnumerator.IsNewSlot = true;
      nongenericGetEnumerator.IsHiddenBySignature = true;
      nongenericGetEnumerator.IsSealed = true;
      iteratorClosure.NonGenericGetEnumerator = nongenericGetEnumerator;
      // Explicitly implements IEnumerable.GetEnumerator();
      IMethodReference nongenericGetEnumeratorOriginal = Dummy.MethodReference;
      foreach (var memref in iteratorClosure.NonGenericIEnumerableInterface.ResolvedType.GetMembersNamed(this.host.NameTable.GetNameFor("GetEnumerator"), false)) {
        IMethodReference mref = memref as IMethodReference;
        if (mref != null) { nongenericGetEnumeratorOriginal = mref; break; }
      }
      MethodImplementation nonGenericGetEnumeratorImp = new MethodImplementation() {
        ContainingType = iteratorClosure.ClosureDefinition,
        ImplementedMethod = nongenericGetEnumeratorOriginal,
        ImplementingMethod = nongenericGetEnumerator
      };
      iteratorClosure.ClosureDefinition.ExplicitImplementationOverrides.Add(nonGenericGetEnumeratorImp);
      // Body: call this.GetEnumerator (the generic version).
      BlockStatement block1 = new BlockStatement();
      block1.Statements.Add(new ReturnStatement() {
        Expression = new MethodCall() {
          IsStaticCall = false,
          MethodToCall = iteratorClosure.GenericGetEnumeratorReference,
          ThisArgument = new ThisReference(),
          Type = iteratorClosure.NonGenericIEnumeratorInterface
        }
      });
      SourceMethodBody body1 = new SourceMethodBody(this.host, this.sourceLocationProvider);
      body1.IsNormalized = true;
      body1.LocalsAreZeroed = true;
      body1.Block = block1;
      body1.MethodDefinition = nongenericGetEnumerator;
      nongenericGetEnumerator.Body = body1;
    }