Microsoft.CodeAnalysis.Razor.Workspaces.RazorDocumentServiceProviderFactory.Create C# (CSharp) Method

Create() public abstract method

public abstract Create ( Microsoft.CodeAnalysis.Razor.Workspaces.DynamicDocumentContainer documentContainer ) : IRazorDocumentServiceProvider
documentContainer Microsoft.CodeAnalysis.Razor.Workspaces.DynamicDocumentContainer
return IRazorDocumentServiceProvider
        public abstract IRazorDocumentServiceProvider Create(DynamicDocumentContainer documentContainer);
    }

Usage Example

Example #1
0
        // Called by us to promote a background document (i.e. assign to a client name). Promoting a background
        // document will allow it to be recognized by the C# server.
        public void PromoteBackgroundDocument(Uri documentUri, IRazorDocumentPropertiesService propertiesService)
        {
            if (documentUri is null)
            {
                throw new ArgumentNullException(nameof(documentUri));
            }

            if (propertiesService is null)
            {
                throw new ArgumentNullException(nameof(propertiesService));
            }

            var filePath = documentUri.GetAbsoluteOrUNCPath().Replace('/', '\\');

            if (!TryGetKeyAndEntry(filePath, out var associatedKvp))
            {
                return;
            }

            var associatedKey   = associatedKvp.Value.Key;
            var associatedEntry = associatedKvp.Value.Value;

            var filename = associatedKey.FilePath + ".g.cs";

            // To promote the background document, we just need to add the passed in properties service to
            // the dynamic file info. The properties service contains the client name and allows the C#
            // server to recognize the document.
            var documentServiceProvider = associatedEntry.Current.DocumentServiceProvider;
            var excerptService          = documentServiceProvider.GetService <IRazorDocumentExcerptService>();
            var mappingService          = documentServiceProvider.GetService <IRazorSpanMappingService>();
            var emptyContainer          = new PromotedDynamicDocumentContainer(
                documentUri, propertiesService, excerptService, mappingService, associatedEntry.Current.TextLoader);

            lock (associatedEntry.Lock)
            {
                associatedEntry.Current = new RazorDynamicFileInfo(
                    filename, associatedEntry.Current.SourceCodeKind, associatedEntry.Current.TextLoader, _factory.Create(emptyContainer));
            }

            Updated?.Invoke(this, filePath);
        }
All Usage Examples Of Microsoft.CodeAnalysis.Razor.Workspaces.RazorDocumentServiceProviderFactory::Create
RazorDocumentServiceProviderFactory