Skip to content

Commit 8b16283

Browse files
committed
Fix build
1 parent ef40ac1 commit 8b16283

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed

src/Aspire.Hosting/IInteractionService.cs

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections;
5+
using System.Diagnostics;
56
using System.Diagnostics.CodeAnalysis;
67

78
namespace Aspire.Hosting;
@@ -108,7 +109,7 @@ public sealed class InteractionInput
108109
/// Gets or sets the name for the input. Used for accessing inputs by name from a keyed collection.
109110
/// If not specified, a name will be generated automatically.
110111
/// </summary>
111-
public string? Name { get; init; }
112+
public string? Name { get; internal set; }
112113

113114
/// <summary>
114115
/// Gets or sets the label for the input.
@@ -175,6 +176,7 @@ public int? MaxLength
175176
/// A collection of interaction inputs that supports both indexed and name-based access.
176177
/// </summary>
177178
[Experimental(InteractionService.DiagnosticId, UrlFormat = "https://aka.ms/aspire/diagnostics/{0}")]
179+
[DebuggerDisplay("Count = {Count}")]
178180
public sealed class InteractionInputCollection : IReadOnlyList<InteractionInput>
179181
{
180182
private readonly IReadOnlyList<InteractionInput> _inputs;
@@ -190,7 +192,7 @@ public InteractionInputCollection(IReadOnlyList<InteractionInput> inputs)
190192
var processedInputs = new List<InteractionInput>();
191193
var inputsByName = new Dictionary<string, InteractionInput>(StringComparer.OrdinalIgnoreCase);
192194
var usedNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
193-
195+
194196
// First pass: collect explicit names and check for duplicates
195197
foreach (var input in inputs)
196198
{
@@ -203,53 +205,39 @@ public InteractionInputCollection(IReadOnlyList<InteractionInput> inputs)
203205
usedNames.Add(input.Name);
204206
}
205207
}
206-
208+
207209
// Second pass: create new inputs with generated names where needed
208-
for (int i = 0; i < inputs.Count; i++)
210+
for (var i = 0; i < inputs.Count; i++)
209211
{
210212
var input = inputs[i];
211213
string finalName;
212-
214+
213215
if (!string.IsNullOrWhiteSpace(input.Name))
214216
{
215217
finalName = input.Name;
216218
}
217219
else
218220
{
219221
// Generate a unique name based on the label or index
220-
string baseName = GenerateBaseName(input.Label);
222+
var baseName = GenerateBaseName(input.Label);
221223
finalName = baseName;
222-
int suffix = 1;
223-
224+
var suffix = 1;
225+
224226
while (usedNames.Contains(finalName))
225227
{
226228
finalName = $"{baseName}_{suffix}";
227229
suffix++;
228230
}
229-
231+
230232
usedNames.Add(finalName);
233+
234+
input.Name = finalName;
231235
}
232-
233-
// Create a new input with the final name if it was generated
234-
var finalInput = string.IsNullOrWhiteSpace(input.Name) ?
235-
new InteractionInput
236-
{
237-
Name = finalName,
238-
Label = input.Label,
239-
Description = input.Description,
240-
EnableDescriptionMarkdown = input.EnableDescriptionMarkdown,
241-
InputType = input.InputType,
242-
Required = input.Required,
243-
Options = input.Options,
244-
Value = input.Value,
245-
Placeholder = input.Placeholder,
246-
MaxLength = input.MaxLength
247-
} : input;
248-
249-
processedInputs.Add(finalInput);
250-
inputsByName[finalName] = finalInput;
236+
237+
processedInputs.Add(input);
238+
inputsByName[finalName] = input;
251239
}
252-
240+
253241
_inputs = processedInputs;
254242
_inputsByName = inputsByName;
255243
}
@@ -260,14 +248,14 @@ private static string GenerateBaseName(string label)
260248
{
261249
return "Input";
262250
}
263-
251+
264252
// Convert to a valid identifier-like name
265253
var chars = label.ToCharArray();
266254
var result = new System.Text.StringBuilder();
267-
268-
for (int i = 0; i < chars.Length; i++)
255+
256+
for (var i = 0; i < chars.Length; i++)
269257
{
270-
char c = chars[i];
258+
var c = chars[i];
271259
if (char.IsLetterOrDigit(c))
272260
{
273261
result.Append(c);
@@ -277,9 +265,9 @@ private static string GenerateBaseName(string label)
277265
result.Append('_');
278266
}
279267
}
280-
268+
281269
// Ensure we have a valid name
282-
string name = result.ToString().Trim('_');
270+
var name = result.ToString().Trim('_');
283271
return string.IsNullOrEmpty(name) ? "Input" : name;
284272
}
285273

tests/Shared/TestInteractionService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Aspire.Hosting.Tests;
99

10-
internal sealed record InteractionData(string Title, string? Message, IReadOnlyList<InteractionInput> Inputs, InteractionOptions? Options, TaskCompletionSource<object> CompletionTcs);
10+
internal sealed record InteractionData(string Title, string? Message, InteractionInputCollection Inputs, InteractionOptions? Options, TaskCompletionSource<object> CompletionTcs);
1111

1212
internal sealed class TestInteractionService : IInteractionService
1313
{
@@ -32,7 +32,7 @@ public Task<InteractionResult<InteractionInput>> PromptInputAsync(string title,
3232

3333
public async Task<InteractionResult<InteractionInputCollection>> PromptInputsAsync(string title, string? message, IReadOnlyList<InteractionInput> inputs, InputsDialogInteractionOptions? options = null, CancellationToken cancellationToken = default)
3434
{
35-
var data = new InteractionData(title, message, inputs, options, new TaskCompletionSource<object>());
35+
var data = new InteractionData(title, message, new InteractionInputCollection(inputs), options, new TaskCompletionSource<object>());
3636
Interactions.Writer.TryWrite(data);
3737
var result = (InteractionResult<IReadOnlyList<InteractionInput>>)await data.CompletionTcs.Task;
3838

@@ -47,7 +47,7 @@ public async Task<InteractionResult<InteractionInputCollection>> PromptInputsAsy
4747

4848
public async Task<InteractionResult<bool>> PromptNotificationAsync(string title, string message, NotificationInteractionOptions? options = null, CancellationToken cancellationToken = default)
4949
{
50-
var data = new InteractionData(title, message, [], options, new TaskCompletionSource<object>());
50+
var data = new InteractionData(title, message, new InteractionInputCollection([]), options, new TaskCompletionSource<object>());
5151
Interactions.Writer.TryWrite(data);
5252
return (InteractionResult<bool>)await data.CompletionTcs.Task;
5353
}

0 commit comments

Comments
 (0)