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>(); var diagnostics = _documentNode.GetAllDiagnostics(); for (var i = 0; i < diagnostics.Count; i++) { Diagnostics.Add(diagnostics[i]); } _scopes = new List <ScopeInternal>(); _scopes.Add(new ScopeInternal(nodeWriter)); }
public override void RenderNode(IntermediateNode node, IntermediateNodeWriter writer) { if (node == null) { throw new ArgumentNullException(nameof(node)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _scopes.Add(new ScopeInternal(writer)); Visitor.Visit(node); _scopes.RemoveAt(_scopes.Count - 1); }
public static CodeRenderingContext CreateRuntime( string newLineString = null, string suppressUniqueIds = "test", RazorSourceDocument source = null, IntermediateNodeWriter nodeWriter = null) { var codeWriter = new CodeWriter(); var documentNode = new DocumentIntermediateNode(); var options = RazorCodeGenerationOptions.CreateDefault(); if (source is null) { source = TestRazorSourceDocument.Create(); } var codeDocument = RazorCodeDocument.Create(source); if (newLineString != null) { codeDocument.Items[CodeRenderingContext.NewLineString] = newLineString; } if (suppressUniqueIds != null) { codeDocument.Items[CodeRenderingContext.SuppressUniqueIds] = suppressUniqueIds; } if (nodeWriter is null) { nodeWriter = new RuntimeNodeWriter(); } var context = new DefaultCodeRenderingContext(codeWriter, nodeWriter, codeDocument, documentNode, options); context.Visitor = new RenderChildrenVisitor(context); return(context); }
public override void RenderChildren(IntermediateNode node, IntermediateNodeWriter writer) { if (node == null) { throw new ArgumentNullException(nameof(node)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _scopes.Add(new ScopeInternal(writer)); _ancestors.Push(node); for (var i = 0; i < node.Children.Count; i++) { Visitor.Visit(node.Children[i]); } _ancestors.Pop(); _scopes.RemoveAt(_scopes.Count - 1); }
public abstract void RenderChildren(IntermediateNode node, IntermediateNodeWriter writer);
public abstract void RenderNode(IntermediateNode node, IntermediateNodeWriter writer);
public ScopeInternal(IntermediateNodeWriter writer) { Writer = writer; }
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>(); 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)); }