static ClassDeclarationSyntax GenerateNewClassDeclarationForDescriptions(BaseTypeDeclarationSyntax classDeclaration,
                                                                                 IReadOnlyCollection <LambdaJobDescription> descriptionsInClass)
        {
            var modifierList = new SyntaxTokenList();

            if (classDeclaration.Modifiers.All(modifier => modifier.Kind() != SyntaxKind.UnsafeKeyword))
            {
                modifierList = modifierList.Add(SyntaxFactory.Token(SyntaxKind.UnsafeKeyword));
            }
            modifierList = modifierList.AddRange(classDeclaration.Modifiers);

            // Create new partial class and mark it as [CompilerGenerated]
            var newClassDeclaration = SyntaxFactory.ClassDeclaration(classDeclaration.Identifier)
                                      .WithBaseList(classDeclaration.BaseList)
                                      .WithModifiers(modifierList)
                                      .WithAttributeLists(SourceGenHelpers.AttributeListFromAttributeName("System.Runtime.CompilerServices.CompilerGenerated"));

            // Replace class methods containing lambda job descriptions
            foreach (var methodDeclaration in classDeclaration.DescendantNodes().OfType <MethodDeclarationSyntax>())
            {
                var descriptionsInMethod = descriptionsInClass.Where(desc => desc.ContainingMethod == methodDeclaration);
                if (!descriptionsInMethod.Any())
                {
                    continue;
                }

                SourceGenHelpers.LogInfo($"  Generating code for method: {methodDeclaration.Identifier}");

                // Generate partial classes and methods for found lambda jobs
                var methodReplacements = new Dictionary <SyntaxNode, SyntaxNode>();
                foreach (var description in descriptionsInMethod)
                {
                    methodReplacements.Add(description.ContainingInvocationExpression, EntitiesSourceFactory.SchedulingInvocationFor(description));
                }
                var methodReplacer = new SyntaxNodeReplacer(methodReplacements);

                var rewrittenMethod = (MethodDeclarationSyntax)methodReplacer.Visit(methodDeclaration);
                if (rewrittenMethod == methodDeclaration)
                {
                    continue;
                }

                // Add rewritten method
                var newModifiers = new SyntaxTokenList(rewrittenMethod.Modifiers.Where(m => !m.IsKind(SyntaxKind.OverrideKeyword)));
                var dotsCompilerPatchedMethodArguments = SyntaxFactory.ParseAttributeArgumentList($"(\"{methodDeclaration.Identifier.Text}\")");
                var dotsCompilerPatchedMethodAttribute = SyntaxFactory.Attribute(SyntaxFactory.IdentifierName("Unity.Entities.DOTSCompilerPatchedMethod"), dotsCompilerPatchedMethodArguments);
                var attributeList = new SyntaxList <AttributeListSyntax>();
                attributeList = attributeList.Add(SyntaxFactory.AttributeList(SyntaxFactory.SeparatedList(new[] { dotsCompilerPatchedMethodAttribute })));

                newClassDeclaration = newClassDeclaration.AddMembers(
                    rewrittenMethod
                    .WithoutPreprocessorTrivia()
                    .WithIdentifier(SyntaxFactory.Identifier(methodDeclaration.Identifier.Text + $"_{Path.GetFileNameWithoutExtension(Path.GetRandomFileName())}"))
                    .WithModifiers(newModifiers)
                    .WithAttributeLists(attributeList)
                    );

                // Add all lambdajob members
                foreach (var description in descriptionsInClass.Where(desc => desc.ContainingMethod == methodDeclaration))
                {
                    newClassDeclaration = newClassDeclaration.AddMembers(EntitiesSourceFactory.JobStructFor(description));
                    if (description.LambdaJobKind == LambdaJobKind.Entities)
                    {
                        newClassDeclaration = newClassDeclaration.AddMembers(EntitiesSourceFactory.EntityQueryFieldFor(description));
                    }
                    newClassDeclaration = newClassDeclaration.AddMembers(EntitiesSourceFactory.ExecuteMethodFor(description));
                    if (description.WithStructuralChangesAndLambdaBodyInSystem)
                    {
                        newClassDeclaration = newClassDeclaration.AddMembers(EntitiesSourceFactory.LambdaBodyMethodFor(description));
                    }
                }
            }

            // Add OnCreateForCompiler method
            newClassDeclaration = newClassDeclaration.AddMembers(EntitiesSourceFactory.OnCreateForCompilerMethodFor(descriptionsInClass));
            return(newClassDeclaration);
        }