Skip to content

Commit b2cb368

Browse files
Copilotdavidfowl
andcommitted
Simplify TryMatchAgainstResources to use foundResource instead of matchCount
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
1 parent 18b403d commit b2cb368

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Aspire.Dashboard/Model/ResourceOutgoingPeerResolver.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ internal static bool TryResolvePeerNameCore(IDictionary<string, ResourceViewMode
210210
private static bool TryMatchAgainstResources(string peerAddress, IDictionary<string, ResourceViewModel> resources, [NotNullWhen(true)] out string? name, [NotNullWhen(true)] out ResourceViewModel? resourceMatch)
211211
{
212212
ResourceViewModel? foundResource = null;
213-
var matchCount = 0;
214213

215214
foreach (var (_, resource) in resources)
216215
{
@@ -222,21 +221,27 @@ private static bool TryMatchAgainstResources(string peerAddress, IDictionary<str
222221
{
223222
foundResource = resource;
224223
}
225-
matchCount++;
224+
else if (foundResource != resource)
225+
{
226+
// Multiple different resources match - return false immediately
227+
name = null;
228+
resourceMatch = null;
229+
return false;
230+
}
226231
break; // No need to check other addresses for this resource once we found a match
227232
}
228233
}
229234
}
230235

231236
// Return true only if exactly one resource matched
232-
if (matchCount == 1 && foundResource is not null)
237+
if (foundResource is not null)
233238
{
234239
name = ResourceViewModel.GetResourceName(foundResource, resources);
235240
resourceMatch = foundResource;
236241
return true;
237242
}
238243

239-
// Return false if no matches or multiple matches found
244+
// Return false if no matches found
240245
name = null;
241246
resourceMatch = null;
242247
return false;

0 commit comments

Comments
 (0)