Skip to content

Commit bd71ca2

Browse files
committed
Apply new suggestions from Resharper EAP
1 parent 45263c2 commit bd71ca2

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

src/JsonApiDotNetCore/Configuration/ResourceDescriptorAssemblyCache.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ internal sealed class ResourceDescriptorAssemblyCache
1212

1313
public void RegisterAssembly(Assembly assembly)
1414
{
15-
if (!_resourceDescriptorsPerAssembly.ContainsKey(assembly))
16-
{
17-
_resourceDescriptorsPerAssembly[assembly] = null;
18-
}
15+
_resourceDescriptorsPerAssembly.TryAdd(assembly, null);
1916
}
2017

2118
public IReadOnlyCollection<ResourceDescriptor> GetResourceDescriptors()

src/JsonApiDotNetCore/Middleware/JsonApiRoutingConvention.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ public void Apply(ApplicationModel application)
101101
$"resource type '{resourceClrType}', which does not exist in the resource graph.");
102102
}
103103

104-
if (_controllerPerResourceTypeMap.ContainsKey(resourceType))
104+
if (_controllerPerResourceTypeMap.TryGetValue(resourceType, out ControllerModel? existingModel))
105105
{
106106
throw new InvalidConfigurationException(
107-
$"Multiple controllers found for resource type '{resourceType}': '{_controllerPerResourceTypeMap[resourceType].ControllerType}' and '{controller.ControllerType}'.");
107+
$"Multiple controllers found for resource type '{resourceType}': '{existingModel.ControllerType}' and '{controller.ControllerType}'.");
108108
}
109109

110110
_resourceTypePerControllerTypeMap.Add(controller.ControllerType, resourceType);
@@ -119,10 +119,10 @@ public void Apply(ApplicationModel application)
119119

120120
string template = TemplateFromResource(controller) ?? TemplateFromController(controller);
121121

122-
if (_registeredControllerNameByTemplate.ContainsKey(template))
122+
if (_registeredControllerNameByTemplate.TryGetValue(template, out string? controllerName))
123123
{
124124
throw new InvalidConfigurationException(
125-
$"Cannot register '{controller.ControllerType.FullName}' for template '{template}' because '{_registeredControllerNameByTemplate[template]}' was already registered for this template.");
125+
$"Cannot register '{controller.ControllerType.FullName}' for template '{template}' because '{controllerName}' was already registered for this template.");
126126
}
127127

128128
_registeredControllerNameByTemplate.Add(template, controller.ControllerType.FullName!);

src/JsonApiDotNetCore/Queries/Internal/QueryableBuilding/SelectClauseBuilder.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,7 @@ private static void IncludeEagerLoads(ResourceType resourceType, Dictionary<Prop
185185

186186
// When an entity navigation property is decorated with both EagerLoadAttribute and RelationshipAttribute,
187187
// it may already exist with a sub-layer. So do not overwrite in that case.
188-
if (!propertySelectors.ContainsKey(propertySelector.Property))
189-
{
190-
propertySelectors[propertySelector.Property] = propertySelector;
191-
}
188+
propertySelectors.TryAdd(propertySelector.Property, propertySelector);
192189
}
193190
}
194191

0 commit comments

Comments
 (0)