-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathTargetFrameworkSelectionPrompt.cs
More file actions
28 lines (21 loc) · 1.14 KB
/
TargetFrameworkSelectionPrompt.cs
File metadata and controls
28 lines (21 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.DotNet.Watch;
internal abstract class TargetFrameworkSelectionPrompt : IDisposable
{
public IReadOnlyList<string>? PreviousTargetFrameworks { get; set; }
public string? PreviousSelection { get; set; }
public async ValueTask<string> SelectAsync(IReadOnlyList<string> targetFrameworks, CancellationToken cancellationToken)
{
var orderedTargetFrameworks = targetFrameworks.Order(StringComparer.OrdinalIgnoreCase).ToArray();
if (PreviousSelection != null && PreviousTargetFrameworks?.SequenceEqual(orderedTargetFrameworks, StringComparer.OrdinalIgnoreCase) == true)
{
return PreviousSelection;
}
PreviousTargetFrameworks = orderedTargetFrameworks;
PreviousSelection = await PromptAsync(targetFrameworks, cancellationToken);
return PreviousSelection;
}
protected abstract Task<string> PromptAsync(IReadOnlyList<string> targetFrameworks, CancellationToken cancellationToken);
public virtual void Dispose() { }
}