public async Task <DynamicFileInfo?> GetDynamicFileInfoAsync(
            ProjectId projectId,
            string projectFilePath,
            string filePath,
            CancellationToken cancellationToken
            )
        {
            // We lazily attach to the dynamic file info provider in order to ensure that Razor assemblies are not loaded in non-Razor contexts.
            if (!EnsureAttached())
            {
                // Razor workload is not installed. Can't build dynamic file infos for any Razor files.
                return(null);
            }

            var result = await _innerDynamicFileInfoProvider.Value
                         .GetDynamicFileInfoAsync(projectId, projectFilePath, filePath, cancellationToken)
                         .ConfigureAwait(false);

            var serviceProvider = new RazorDocumentServiceProviderWrapper(
                result.DocumentServiceProvider
                );
            var razorDocumentPropertiesService =
                result.DocumentServiceProvider.GetService <IRazorDocumentPropertiesService>();
            var designTimeOnly  = razorDocumentPropertiesService?.DesignTimeOnly ?? false;
            var dynamicFileInfo = new DynamicFileInfo(
                result.FilePath,
                result.SourceCodeKind,
                result.TextLoader,
                designTimeOnly,
                serviceProvider
                );

            return(dynamicFileInfo);
        }
Ejemplo n.º 2
0
 public static DocumentInfo Create(
     DocumentId id,
     string name,
     IEnumerable <string>?folders,
     SourceCodeKind sourceCodeKind,
     TextLoader?loader,
     string?filePath,
     bool isGenerated,
     RazorDocumentServiceProviderWrapper documentServiceProvider)
 {
     return(DocumentInfo.Create(id, name, folders.ToBoxedImmutableArray(), sourceCodeKind, loader, filePath, isGenerated, documentServiceProvider));
 }
        public DocumentInfo CreateDocumentInfo(
            DocumentId id,
            string name,
            IReadOnlyList <string>?folders = null,
            SourceCodeKind sourceCodeKind  = SourceCodeKind.Regular,
            TextLoader?loader   = null,
            string?filePath     = null,
            bool isGenerated    = false,
            bool designTimeOnly = false,
            IRazorDocumentServiceProvider?razorDocumentServiceProvider = null)
        {
            folders ??= new List <string>();

            IDocumentServiceProvider?documentServiceProvider = null;

            if (razorDocumentServiceProvider is not null)
            {
                documentServiceProvider = new RazorDocumentServiceProviderWrapper(razorDocumentServiceProvider);
            }

            return(DocumentInfo.Create(id, name, folders, sourceCodeKind, loader, filePath, isGenerated, designTimeOnly, documentServiceProvider));
        }