Exemplo n.º 1
0
        protected override RazorCodeDocument CreateCodeDocumentDesignTimeCore(RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException(nameof(projectItem));
            }

            return(CreateCodeDocumentDesignTimeCore(projectItem, configureParser: null, configureCodeGeneration: null));
        }
 /// <summary>
 /// Gets the sequence of imports with the name specified by <see cref="P:Microsoft.AspNetCore.Razor.Language.RazorTemplateEngineOptions.ImportsFileName" />
 /// that apply to <paramref name="path" />.
 /// </summary>
 /// <param name="path">The path to look up import items for.</param>
 /// <returns>A sequence of <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorProjectItem" /> instances that apply to the
 /// <paramref name="path" />.</returns>
 // Token: 0x0600046B RID: 1131 RVA: 0x00009FCC File Offset: 0x000081CC
 public IEnumerable <Microsoft.AspNetCore.Razor.Language.RazorProjectItem> GetImportItems(string path)
 {
     if (string.IsNullOrEmpty(path))
     {
         throw new ArgumentException("Argument path Cannot Be Null Or Empty");
     }
     Microsoft.AspNetCore.Razor.Language.RazorProjectItem item = this.Project.GetItem(path);
     return(this.GetImportItems(item));
 }
 /// <summary>
 /// Parses the template specified by the project item <paramref name="path" />.
 /// </summary>
 /// <param name="path">The template path.</param>
 /// <returns>The <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument" />.</returns>
 // Token: 0x06000464 RID: 1124 RVA: 0x00009DD8 File Offset: 0x00007FD8
 public Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument GenerateCode(string path)
 {
     if (string.IsNullOrEmpty(path))
     {
         throw new ArgumentException("Argument path Cannot Be Null Or Empty");
     }
     Microsoft.AspNetCore.Razor.Language.RazorProjectItem item = this.Project.GetItem(path);
     return(this.GenerateCode(item));
 }
        public void Add(RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException(nameof(projectItem));
            }

            var filePath = NormalizeAndEnsureValidPath(projectItem.FilePath);

            _root.AddFile(new FileNode(filePath, projectItem));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the sequence of imports with the name specified by <see cref="P:RazorTemplateEngineOptions.ImportsFileName" />
        /// that apply to <paramref name="projectItem" />.
        /// </summary>
        /// <param name="projectItem">The <see cref="T:RazorProjectItem" /> to look up import items for.</param>
        /// <returns>A sequence of <see cref="T:RazorProjectItem" /> instances that apply to the
        /// <paramref name="projectItem" />.</returns>
        public virtual IEnumerable <RazorProjectItem> GetImportItems(RazorProjectItem projectItem)
        {
            string importsFileName = this.Options.ImportsFileName;

            if (!string.IsNullOrEmpty(importsFileName))
            {
                return(this.Project.FindHierarchicalItems(projectItem.FilePath, importsFileName));
            }

            return(Enumerable.Empty <RazorProjectItem>());
        }
Exemplo n.º 6
0
        public virtual RazorCodeDocument ProcessDesignTime(RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException(nameof(projectItem));
            }

            var codeDocument = CreateCodeDocumentDesignTimeCore(projectItem);

            ProcessCore(codeDocument);
            return(codeDocument);
        }
Exemplo n.º 7
0
        // Internal for testing
        internal static RazorSourceDocument ConvertToSourceDocument(RazorProjectItem importItem)
        {
            if (importItem.Exists)
            {
                // Normal import, has file paths, content etc.
                return(RazorSourceDocument.ReadFrom(importItem));
            }

            // Marker import, doesn't exist, used as an identifier for "there could be something here".
            var sourceDocumentProperties = new RazorSourceDocumentProperties(importItem.FilePath, importItem.RelativePhysicalPath);

            return(RazorSourceDocument.Create(string.Empty, sourceDocumentProperties));
        }
 /// <summary>
 /// Parses the template specified by <paramref name="projectItem" />.
 /// </summary>
 /// <param name="projectItem">The <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorProjectItem" />.</param>
 /// <returns>The <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument" />.</returns>
 // Token: 0x06000465 RID: 1125 RVA: 0x00009E14 File Offset: 0x00008014
 public Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument GenerateCode(Microsoft.AspNetCore.Razor.Language.RazorProjectItem projectItem)
 {
     if (projectItem == null)
     {
         throw new ArgumentNullException("projectItem");
     }
     if (!projectItem.Exists)
     {
         throw new InvalidOperationException($"FormatRazorTemplateEngine_ItemCouldNotBeFound {projectItem.FilePath}");
     }
     Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument = this.CreateCodeDocument(projectItem);
     return(this.GenerateCode(codeDocument));
 }
        public IReadOnlyList <RazorProjectItem> GetImports(RazorProjectItem projectItem)
        {
            if (projectItem is null)
            {
                throw new ArgumentNullException(nameof(projectItem));
            }

            var imports = new List <RazorProjectItem>();

            AddHierarchicalImports(projectItem, imports);

            return(imports);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Parses the template specified by <paramref name="projectItem" />.
        /// </summary>
        /// <param name="projectItem">The <see cref="T:RazorProjectItem" />.</param>
        /// <returns>The <see cref="T:RazorCSharpDocument" />.</returns>
        public RazorCSharpDocument GenerateCode(RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException("projectItem");
            }

            if (!projectItem.Exists)
            {
                throw new InvalidOperationException($"FormatRazorTemplateEngine_ItemCouldNotBeFound {projectItem.FilePath}");
            }

            return(this.GenerateCode(this.CreateCodeDocument(projectItem)));
        }
Exemplo n.º 11
0
        protected override RazorCodeDocument CreateCodeDocumentDesignTimeCore(RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException(nameof(projectItem));
            }

            var sourceDocument = RazorSourceDocument.ReadFrom(projectItem);

            var importFeature         = GetRequiredFeature <IImportProjectFeature>();
            var importItems           = importFeature.GetImports(projectItem);
            var importSourceDocuments = GetImportSourceDocuments(importItems, suppressExceptions: true);

            return(CreateCodeDocumentDesignTimeCore(sourceDocument, importSourceDocuments, tagHelpers: null));
        }
Exemplo n.º 12
0
        public override RazorCodeDocument ProcessDeclarationOnly(RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException(nameof(projectItem));
            }

            var codeDocument = CreateCodeDocumentCore(projectItem, configureParser: null, configureCodeGeneration: (builder) =>
            {
                builder.SuppressPrimaryMethodBody = true;
            });

            ProcessCore(codeDocument);
            return(codeDocument);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Parses the template specified by <paramref name="projectItem"/>.
        /// </summary>
        /// <param name="projectItem">The <see cref="RazorProjectItem"/>.</param>
        /// <returns>The <see cref="RazorCSharpDocument"/>.</returns>
        public RazorCSharpDocument GenerateCode(RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException(nameof(projectItem));
            }

            if (!projectItem.Exists)
            {
                throw new InvalidOperationException(Resources.FormatRazorTemplateEngine_ItemCouldNotBeFound(projectItem.FilePath));
            }

            var codeDocument = CreateCodeDocument(projectItem);

            return(GenerateCode(codeDocument));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Generates a <see cref="T:RazorCodeDocument" /> for the specified <paramref name="projectItem" />.
        /// </summary>
        /// <param name="projectItem">The <see cref="T:RazorProjectItem" />.</param>
        /// <returns>The created <see cref="T:RazorCodeDocument" />.</returns>
        public virtual RazorCodeDocument CreateCodeDocument(RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException("projectItem");
            }

            if (!projectItem.Exists)
            {
                throw new InvalidOperationException($"FormatRazorTemplateEngine_ItemCouldNotBeFound {projectItem.FilePath}");
            }

            var source  = RazorSourceDocument.ReadFrom(projectItem);
            var imports = this.GetImports(projectItem);

            return(RazorCodeDocument.Create(source, imports));
        }
Exemplo n.º 15
0
        protected override RazorCodeDocument CreateCodeDocumentDesignTimeCore(RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException(nameof(projectItem));
            }

            var sourceDocument = RazorSourceDocument.ReadFrom(projectItem);

            var importFeature         = GetRequiredFeature <IImportProjectFeature>();
            var importItems           = importFeature.GetImports(projectItem);
            var importSourceDocuments = GetImportSourceDocuments(importItems, suppressExceptions: true);

            var parserOptions         = GetRequiredFeature <IRazorParserOptionsFactoryProjectFeature>().Create(ConfigureDesignTimeParserOptions);
            var codeGenerationOptions = GetRequiredFeature <IRazorCodeGenerationOptionsFactoryProjectFeature>().Create(ConfigureDesignTimeCodeGenerationOptions);

            return(RazorCodeDocument.Create(sourceDocument, importSourceDocuments, parserOptions, codeGenerationOptions));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Reads the <see cref="RazorSourceDocument"/> from the specified <paramref name="projectItem"/>.
        /// </summary>
        /// <param name="projectItem">The <see cref="RazorProjectItem"/> to read from.</param>
        /// <returns>The <see cref="RazorSourceDocument"/>.</returns>
        public static RazorSourceDocument ReadFrom(RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException(nameof(projectItem));
            }

            var path = projectItem.PhysicalPath;

            if (string.IsNullOrEmpty(path))
            {
                path = projectItem.FilePath;
            }

            using (var inputStream = projectItem.Read())
            {
                return(ReadFrom(inputStream, path));
            }
        }
Exemplo n.º 17
0
        protected RazorCodeDocument CreateCodeDocumentCore(
            RazorProjectItem projectItem,
            Action <RazorParserOptionsBuilder> configureParser,
            Action <RazorCodeGenerationOptionsBuilder> configureCodeGeneration)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException(nameof(projectItem));
            }

            var sourceDocument = RazorSourceDocument.ReadFrom(projectItem);

            var importItems = new List <RazorProjectItem>();
            var features    = ProjectFeatures.OfType <IImportProjectFeature>();

            foreach (var feature in features)
            {
                importItems.AddRange(feature.GetImports(projectItem));
            }

            var importSourceDocuments = GetImportSourceDocuments(importItems);

            return(CreateCodeDocumentCore(sourceDocument, projectItem.FileKind, importSourceDocuments, tagHelpers: null, configureParser, configureCodeGeneration, cssScope: projectItem.CssScope));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Gets <see cref="T:RazorSourceDocument" /> that are applicable to the specified <paramref name="projectItem" />.
        /// </summary>
        /// <param name="projectItem">The <see cref="T:RazorProjectItem" />.</param>
        /// <returns>The sequence of applicable <see cref="T:RazorSourceDocument" />.</returns>
        public virtual IEnumerable <RazorSourceDocument> GetImports(RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException("projectItem");
            }

            var list = new List <RazorSourceDocument>();

            foreach (var razorProjectItem in this.GetImportItems(projectItem))
            {
                if (razorProjectItem.Exists)
                {
                    list.Insert(0, RazorSourceDocument.ReadFrom(razorProjectItem));
                }
            }

            if (this.Options.DefaultImports != null)
            {
                list.Insert(0, this.Options.DefaultImports);
            }

            return(list);
        }
Exemplo n.º 19
0
 protected abstract RazorCodeDocument CreateCodeDocumentDesignTimeCore(RazorProjectItem projectItem);
Exemplo n.º 20
0
 public virtual RazorCodeDocument ProcessDeclarationOnly(RazorProjectItem projectItem)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 21
0
 public FileNode(string path, RazorProjectItem projectItem)
 {
     Path        = path;
     ProjectItem = projectItem;
 }
Exemplo n.º 22
0
 public IReadOnlyList <RazorProjectItem> GetImports(RazorProjectItem projectItem) => Array.Empty <RazorProjectItem>();
Exemplo n.º 23
0
 public IReadOnlyList <RazorProjectItem> GetImports(RazorProjectItem projectItem)
 {
     return(_imports);
 }
        /// <summary>
        /// Generates a <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorCodeDocument" /> for the specified <paramref name="projectItem" />.
        /// </summary>
        /// <param name="projectItem">The <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorProjectItem" />.</param>
        /// <returns>The created <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorCodeDocument" />.</returns>
        // Token: 0x06000468 RID: 1128 RVA: 0x00009EB8 File Offset: 0x000080B8
        public virtual Microsoft.AspNetCore.Razor.Language.RazorCodeDocument CreateCodeDocument(Microsoft.AspNetCore.Razor.Language.RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException("projectItem");
            }
            if (!projectItem.Exists)
            {
                throw new InvalidOperationException($"FormatRazorTemplateEngine_ItemCouldNotBeFound {projectItem.FilePath}");
            }
            Microsoft.AspNetCore.Razor.Language.RazorSourceDocument source = Microsoft.AspNetCore.Razor.Language.RazorSourceDocument.ReadFrom(projectItem);
            IEnumerable <Microsoft.AspNetCore.Razor.Language.RazorSourceDocument> imports = this.GetImports(projectItem);

            return(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument.Create(source, imports));
        }
        /// <summary>
        /// Gets <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorSourceDocument" /> that are applicable to the specified <paramref name="projectItem" />.
        /// </summary>
        /// <param name="projectItem">The <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorProjectItem" />.</param>
        /// <returns>The sequence of applicable <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorSourceDocument" />.</returns>
        // Token: 0x0600046A RID: 1130 RVA: 0x00009F3C File Offset: 0x0000813C
        public virtual IEnumerable <Microsoft.AspNetCore.Razor.Language.RazorSourceDocument> GetImports(Microsoft.AspNetCore.Razor.Language.RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException("projectItem");
            }
            List <Microsoft.AspNetCore.Razor.Language.RazorSourceDocument> list = new List <Microsoft.AspNetCore.Razor.Language.RazorSourceDocument>();

            foreach (Microsoft.AspNetCore.Razor.Language.RazorProjectItem razorProjectItem in this.GetImportItems(projectItem))
            {
                if (razorProjectItem.Exists)
                {
                    list.Insert(0, Microsoft.AspNetCore.Razor.Language.RazorSourceDocument.ReadFrom(razorProjectItem));
                }
            }
            if (this.Options.DefaultImports != null)
            {
                list.Insert(0, this.Options.DefaultImports);
            }
            return(list);
        }