public static void Rewrite(RewriteDesign design, RewrittenValueBridge[] args) { var enlarging = args.FirstOrDefault()?.ToString() switch { "EnlargingCoefficient.By2" => 1, "EnlargingCoefficient.By4" => 2, "EnlargingCoefficient.By8" => 3, _ when design.SourceSize != null => 2, _ => 1 }; var(currentLength, currentResult) = RewriteToArray.GetResultVariable(design, design.LastValue.Type); VariableBridge result = RewriteToArray.RewriteOther(design, currentLength, currentResult, enlarging); RewriteToArray.SimplifyPart(design, result); var listResultType = ParseTypeName($"LinqRewrite.Core.SimpleList.SimpleList<{design.LastValue.Type}>"); LocalVariable finalResult = CreateGlobalVariable(design, listResultType); design.ResultAdd(finalResult.Assign(New(listResultType))); design.ResultAdd(finalResult.Access("Items").Assign(result)); design.ResultAdd(finalResult.Access("Count").Assign(design.ResultSize ?? design.Indexer)); design.ResultAdd(Return(finalResult)); } }
public static StatementSyntax[] GetForEachStatement(RewriteDesign design, LocalVariable enumeratorVariable, List <IStatementSyntax> loopContent) { if (design.Unchecked) { return new StatementSyntax[] { While(enumeratorVariable.Access("MoveNext").Invoke(), GetBody(design, loopContent) ), (StatementBridge)enumeratorVariable.Access("Dispose").Invoke() } } ; return(new StatementSyntax[] { TryF(Block( (StatementBridge)While(enumeratorVariable.Access("MoveNext").Invoke(), GetBody(design, loopContent) ) ), Block( (StatementBridge)enumeratorVariable.Access("Dispose").Invoke() )) }); }