It's very common to look up resources like this:
var dashboardResource = model.Resources.SingleOrDefault(r => StringComparers.ResourceName.Equals(r.Name, KnownResourceNames.AspireDashboard));
This is verbose, error prone, creates duplication, and could have performance issues.
It could be fixed by adding a TryGetByName method to IResourceCollection. It would be a DIM that by default uses the enumerator to get the resource name. But ResourceCollection overrides it to get the resource from a private Dictionary<string, IResource> that is kept in sync with _resources`.
Existing code that loops over the resources collection to get a resource by name can use the new method.
It's very common to look up resources like this:
This is verbose, error prone, creates duplication, and could have performance issues.
It could be fixed by adding a
TryGetByNamemethod toIResourceCollection. It would be a DIM that by default uses the enumerator to get the resource name. ButResourceCollectionoverrides it to get the resource from a privateDictionary<string, IResource> that is kept in sync with_resources`.Existing code that loops over the resources collection to get a resource by name can use the new method.