/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/EditorFeatures/TestUtilities/TextEditorFactoryExtensions.cs
51 строка
2 KB
Cyrus Najmabadi
Use implicit object creation expressions
13 сен 2025, 01:48
13 сен 2025, 01:48
4c6a36a
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #nullable disable using System; using System.Collections.Immutable; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; namespace Microsoft.CodeAnalysis.Editor.UnitTests; internal static class TextEditorFactoryExtensions { public static DisposableTextView CreateDisposableTextView(this ITextEditorFactoryService textEditorFactory) => new(textEditorFactory.CreateTextView()); public static DisposableTextView CreateDisposableTextView(this ITextEditorFactoryService textEditorFactory, ITextBuffer buffer, ImmutableArray<string> roles = default) { // Every default role but outlining. Starting in 15.2, the editor // OutliningManager imports JoinableTaskContext in a way that's // difficult to satisfy in our unit tests. Since we don't directly // depend on it, just disable it if (roles.IsDefault) { roles = [ PredefinedTextViewRoles.Analyzable, PredefinedTextViewRoles.Document, PredefinedTextViewRoles.Editable, PredefinedTextViewRoles.Interactive, PredefinedTextViewRoles.Zoomable, ]; } var roleSet = textEditorFactory.CreateTextViewRoleSet(roles); return new DisposableTextView(textEditorFactory.CreateTextView(buffer, roleSet)); } } public class DisposableTextView : IDisposable { public DisposableTextView(IWpfTextView textView) => this.TextView = textView; public IWpfTextView TextView { get; } public void Dispose() => TextView.Close(); }