예제 #1
0
        // Internal for testing
        internal void UpdateRazorHostProject()
        {
            _foregroundDispatcher.AssertForegroundThread();

            DetachCurrentRazorProjectHost();

            if (!_projectService.IsSupportedProject(_project))
            {
                // Not a Razor compatible project.
                return;
            }

            if (!TryGetProjectSnapshotManager(out var projectSnapshotManager))
            {
                // Could not get a ProjectSnapshotManager for the current project.
                return;
            }

            if (_project.IsCapabilityMatch(ExplicitRazorConfigurationCapability))
            {
                // SDK >= 2.1
                _razorProjectHost = new DefaultRazorProjectHost(_project, _foregroundDispatcher, projectSnapshotManager);
                return;
            }

            // We're an older version of Razor at this point, SDK < 2.1
            _razorProjectHost = new FallbackRazorProjectHost(_project, _foregroundDispatcher, projectSnapshotManager);
        }
        // Internal for testing
        internal void UpdateRazorHostProject()
        {
            _ = _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
            {
                DetachCurrentRazorProjectHost();

                if (!_projectService.IsSupportedProject(_project))
                {
                    // Not a Razor compatible project.
                    return;
                }

                if (!TryGetProjectSnapshotManager(out var projectSnapshotManager))
                {
                    // Could not get a ProjectSnapshotManager for the current project.
                    return;
                }

                if (_project.IsCapabilityMatch(ExplicitRazorConfigurationCapability))
                {
                    // SDK >= 2.1
                    _razorProjectHost = new DefaultRazorProjectHost(_project, _projectSnapshotManagerDispatcher, projectSnapshotManager);
                    return;
                }

                // We're an older version of Razor at this point, SDK < 2.1
                _razorProjectHost = new FallbackRazorProjectHost(_project, _projectSnapshotManagerDispatcher, projectSnapshotManager);
            }, CancellationToken.None);
        }
예제 #3
0
 private void DetachCurrentRazorProjectHost()
 {
     _razorProjectHost?.Detach();
     _razorProjectHost = null;
 }