public static void RewriteOther(RewriteDesign design, CollectionValueBridge collection, LocalVariable variable = null, bool otherIndexer = false, bool?reuseVariables = null) { if (collection.CollectionType == CollectionType.Array || collection.CollectionType == CollectionType.List || collection.CollectionType == CollectionType.IList || collection.CollectionType == CollectionType.SimpleList) { ArrayEnumeration(design, collection.ItemType, collection.Count, collection, variable); } else if (collection.CollectionType == CollectionType.IEnumerable) { EnumerableEnumeration(design, collection, variable); } if (otherIndexer) { design.CurrentIterator.Indexer = null; } }
public static void EnumerableEnumeration(RewriteDesign design, CollectionValueBridge collection, LocalVariable variable = null) { design.CurrentIterator.ForFrom = null; design.CurrentIterator.ForTo = null; design.CurrentIterator.Enumerator = CreateGlobalVariable(design, ParseTypeName($"System.Collections.Generic.IEnumerator<{collection.ItemType}>")); design.CurrentIterator.ListEnumeration = false; if (variable == null) { design.LastValue = new TypedValueBridge(collection.ItemType, design.CurrentIterator.Enumerator.Access("Current")); } else { design.CurrentForAdd(variable.Assign(design.CurrentIterator.Enumerator.Access("Current"))); design.LastValue = new TypedValueBridge(collection.ItemType, variable); } design.SourceSize = null; var listEnumerations = design.Iterators.Select(x => x.ListEnumeration).ToArray(); design.ListEnumeration = false; listEnumerations.Select((x, i) => (x, i)).ForEach(x => design.Iterators[x.i].ListEnumeration = x.x); design.ModifiedEnumeration = true; }