private void CreateAnonymousGeneratorType() { // Set up some important types _sourceItemType = TypeSystemServices.ObjectType; _sourceEnumeratorType = TypeSystemServices.IEnumeratorType; _sourceEnumerableType = TypeSystemServices.IEnumerableType; _resultEnumeratorType = TypeSystemServices.IEnumeratorGenericType.GenericInfo.ConstructType(_skeleton.GeneratorItemType); _enumerator = _collector.CreateSkeletonClass("Enumerator", _generator.LexicalInfo); // use a generic enumerator for the source type if possible _sourceItemType = TypeSystemServices.GetGenericEnumerableItemType(_generator.Iterator.ExpressionType); if (_sourceItemType != null && _sourceItemType != TypeSystemServices.ObjectType) { _sourceEnumerableType = TypeSystemServices.IEnumerableGenericType.GenericInfo.ConstructType(_sourceItemType); _sourceEnumeratorType = TypeSystemServices.IEnumeratorGenericType.GenericInfo.ConstructType(_sourceItemType); } else { _sourceItemType = TypeSystemServices.ObjectType; } // Add base types _enumerator.AddBaseType(_resultEnumeratorType); _enumerator.AddBaseType(TypeSystemServices.Map(typeof(ICloneable))); _enumerator.AddBaseType(TypeSystemServices.IDisposableType); // Add fields _enumeratorField = _enumerator.AddField("$$enumerator", _sourceEnumeratorType); _current = _enumerator.AddField("$$current", _skeleton.GeneratorItemType); // Add methods CreateReset(); CreateCurrent(); CreateMoveNext(); CreateClone(); CreateDispose(); EnumeratorConstructorMustCallReset(); _collector.AdjustReferences(); BooClassBuilder generatorClassBuilder = _skeleton.GeneratorClassBuilder; _collector.DeclareFieldsAndConstructor(generatorClassBuilder); CreateGetEnumerator(); generatorClassBuilder.ClassDefinition.Members.Add(_enumerator.ClassDefinition); }