Ejemplo n.º 1
0
        private static (bool preCheck, ExpressionSyntax result) TryRewriteSimple(RewriteDesign design, string[] names)
        {
            if (design.CurrentCollection?.CollectionType == CollectionType.IEnumerable)
            {
                return(false, null);
            }
            if (names.Any(x => MethodsModifyingEnumeration.Contains(x)))
            {
                return(false, null);
            }
            if (design.Data.CurrentMethodParams.Any(x => x.Modifiers.Any()))
            {
                return(false, null);
            }

            if (!MethodsCreateArray.Contains(names.First()))
            {
                RewriteCollectionEnumeration.Rewrite(design, Array.Empty <RewrittenValueBridge>(), false);
            }
            for (var i = 0; i < names.Length; i++)
            {
                ExpressionSyntax rewrittenPart = RewriteSimplePart(names[i], design, i);
                if (design.Error)
                {
                    return(true, null);
                }
                if (!design.SimpleEnumeration)
                {
                    return(true, null);
                }
                if (rewrittenPart != null)
                {
                    return(true, rewrittenPart);
                }
            }

            if (!MethodsWithResult.Contains(names.Last()))
            {
                ExpressionSyntax rewrittenPart = RewriteToArray.SimpleRewrite(design, Array.Empty <RewrittenValueBridge>());
                if (!design.SimpleEnumeration)
                {
                    return(true, null);
                }
                if (rewrittenPart != null)
                {
                    return(true, rewrittenPart);
                }
            }

            return(true, null);
        }
Ejemplo n.º 2
0
        private static void RewriteComposite(RewriteDesign design, string[] names)
        {
            if (design.Data.CurrentMethodIsConditional && design.ReturnType.Type.ToString() == "void")
            {
                design.InitialAdd(If(design.CurrentCollection.IsEqual(null), ReturnStatement()));
            }

            if (!MethodsCreateArray.Contains(names.First()))
            {
                RewriteCollectionEnumeration.Rewrite(design, Array.Empty <RewrittenValueBridge>(), true);
            }
            for (var i = 0; i < names.Length; i++)
            {
                design.Variables.Where(x => !x.IsGlobal).ForEach(x => x.IsUsed = false);
                RewritePart(names[i], design, i);
            }

            if (design.HasResultMethod)
            {
                return;
            }
            design.ForAdd(YieldStatement(SyntaxKind.YieldReturnStatement, design.LastValue));
            design.ResultAdd(YieldStatement(SyntaxKind.YieldBreakStatement));
        }