コード例 #1
0
        public static void Rewrite(RewriteDesign design, RewrittenValueBridge[] args)
        {
            var sourceSizeValue = design.SourceSize;
            var collectionValue = args[0];

            if (!AssertNotNull(design, collectionValue))
            {
                return;
            }

            var oldLastValue   = design.LastValue;
            var collectionType = design.Data.GetTypeInfo(collectionValue).Type;
            var oldIterator    = design.InsertIterator(new CollectionValueBridge(design, collectionType, collectionValue, true));

            RewriteCollectionEnumeration.RewriteOther(design, design.CurrentIterator.Collection);

            var hashsetType     = ParseTypeName($"LinqRewrite.Core.SimpleSet<{design.LastValue.Type}>");
            var hashsetCreation = args.Length switch
            {
                1 => New(hashsetType),
                2 => New(hashsetType, args[1])
            };
            var hashsetVariable = CreateGlobalVariable(design, hashsetType, hashsetCreation);

            design.CurrentForAdd(hashsetVariable.Access("Add").Invoke(design.LastValue));
            design.CurrentIterator.Complete = true;

            design.CurrentIterator = oldIterator;
            design.LastValue       = oldLastValue;

            design.LastValue = design.LastValue.Reusable(design);
            design.ForAdd(If(Not(hashsetVariable.Access("Remove").Invoke(design.LastValue)),
                             Continue()));

            if (sourceSizeValue != null && design.SourceSize != null)
            {
                design.SourceSize += sourceSizeValue;
            }
            else
            {
                design.SourceSize = null;
            }

            design.ListEnumeration     = false;
            design.ModifiedEnumeration = true;
        }
    }
コード例 #2
0
        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;
        }