public SourceTreeBuilder() { Root = new CSharpSourceTree(); _activeScopes = new Stack <CSharpBlock>(); _activeScopes.Push(Root); _endBlock = EndBlock; }
public CSharpSourceTree Execute(RazorCodeDocument document, CSharpSourceTree sourceTree) { if (_host.EnableInstrumentation) { Walk(sourceTree); } return(sourceTree); }
public CSharpSourceTree Execute(RazorCodeDocument document, CSharpSourceTree sourceTree) { var modelType = GetDeclaredModelType(sourceTree); var classInfo = document.GetClassName(); if (modelType == null) { // Insert a model directive into the system so sub-systems can rely on the model being the class. var modelTokens = new List <RazorDirectiveToken>() { new RazorDirectiveToken { Descriptor = new RazorDirectiveTokenDescriptor { Type = RazorDirectiveTokenType.Type }, Value = classInfo.Class, } }; var modelDirective = new RazorSingleLineDirective() { Name = "model", Tokens = modelTokens, }; sourceTree.Children.Insert(0, modelDirective); modelType = classInfo.Class; } // Inject properties needed to execute Razor pages. var classDeclaration = FindClassDeclaration(sourceTree); var viewDataType = $"global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<{modelType}>"; classDeclaration.Children.Insert(0, new RenderStatement() { Code = $"public {modelType} Model => ViewData.Model;", }); var viewDataProperty = new RenderStatement { Code = $"public new {viewDataType} ViewData => ({viewDataType})base.ViewData;" }; classDeclaration.Children.Insert(0, viewDataProperty); var injectHtmlHelper = CreateInjectDirective($"Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<{modelType}>", "Html"); sourceTree.Children.Insert(0, injectHtmlHelper); var injectLogger = CreateInjectDirective($"Microsoft.Extensions.Logging.ILogger<{classInfo.Class}>", "Logger"); sourceTree.Children.Insert(0, injectLogger); return(sourceTree); }
public GeneratedCSharpDocument Render(CSharpSourceTree sourceTree) { Render(sourceTree.Children); var generatedCode = _generationContext.Writer.GenerateCode(); var lineMappings = _generationContext.Writer.LineMappingManager.Mappings; var generatedCSharpDocument = new GeneratedCSharpDocument { GeneratedCode = generatedCode, LineMappings = lineMappings, }; return(generatedCSharpDocument); }
public static void SetSourceTree(this RazorCodeDocument document, CSharpSourceTree sourceTree) { if (document == null) { throw new ArgumentNullException(nameof(document)); } if (sourceTree == null) { throw new ArgumentNullException(nameof(sourceTree)); } document.Items[typeof(CSharpSourceTree)] = sourceTree; }
public CSharpSourceTree Execute(RazorCodeDocument document, CSharpSourceTree sourceTree) { var activeDirectives = document.GetCSharpRenderingDirectives(); if (activeDirectives == null) { var discoveredDirectives = new List <IRazorDirective>(); AddDiscoveredDirectives(sourceTree, discoveredDirectives); document.SetCSharpRenderingDirectives(discoveredDirectives); } return(sourceTree); }
public CSharpSourceTree Execute(RazorCodeDocument document, CSharpSourceTree sourceTree) { new PreallocatedAttributeWalker().Walk(sourceTree); return(sourceTree); }
public CSharpSourceTree Execute(RazorCodeDocument document, CSharpSourceTree sourceTree) { Walk(sourceTree); return(sourceTree); }