public DefaultCodeRenderingContext(
        CodeWriter codeWriter,
        IntermediateNodeWriter nodeWriter,
        RazorCodeDocument codeDocument,
        DocumentIntermediateNode documentNode,
        RazorCodeGenerationOptions options)
    {
        if (codeWriter == null)
        {
            throw new ArgumentNullException(nameof(codeWriter));
        }

        if (nodeWriter == null)
        {
            throw new ArgumentNullException(nameof(nodeWriter));
        }

        if (codeDocument == null)
        {
            throw new ArgumentNullException(nameof(codeDocument));
        }

        if (documentNode == null)
        {
            throw new ArgumentNullException(nameof(documentNode));
        }

        if (options == null)
        {
            throw new ArgumentNullException(nameof(options));
        }

        CodeWriter    = codeWriter;
        _codeDocument = codeDocument;
        _documentNode = documentNode;
        Options       = options;

        _ancestors     = new Stack <IntermediateNode>();
        Diagnostics    = new RazorDiagnosticCollection();
        Items          = new ItemCollection();
        SourceMappings = new List <SourceMapping>();
        LinePragmas    = new List <LinePragma>();

        var diagnostics = _documentNode.GetAllDiagnostics();

        for (var i = 0; i < diagnostics.Count; i++)
        {
            Diagnostics.Add(diagnostics[i]);
        }

        var newLineString = codeDocument.Items[NewLineString];

        if (newLineString != null)
        {
            // Set new line character to a specific string regardless of platform, for testing purposes.
            codeWriter.NewLine = (string)newLineString;
        }

        Items[NewLineString]     = codeDocument.Items[NewLineString];
        Items[SuppressUniqueIds] = codeDocument.Items[SuppressUniqueIds];

        _scopes = new List <ScopeInternal>();
        _scopes.Add(new ScopeInternal(nodeWriter));
    }