Skip to content

Commit 9e1f9dc

Browse files
committed
Apply new suggestions from Resharper EAP
1 parent 1c9a7c9 commit 9e1f9dc

File tree

5 files changed

+8
-18
lines changed

5 files changed

+8
-18
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

src/JsonApiDotNetCore/QueryStrings/Internal/PaginationQueryStringParameterReader.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,7 @@ public MutablePaginationEntry ResolveEntryInScope(ResourceFieldChainExpression?
154154
return _globalScope;
155155
}
156156

157-
if (!_nestedScopes.ContainsKey(scope))
158-
{
159-
_nestedScopes.Add(scope, new MutablePaginationEntry());
160-
}
161-
157+
_nestedScopes.TryAdd(scope, new MutablePaginationEntry());
162158
return _nestedScopes[scope];
163159
}
164160

src/JsonApiDotNetCore/Serialization/Response/MetaBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void Add(IDictionary<string, object?> values)
3030
{
3131
ArgumentGuard.NotNull(values);
3232

33-
_meta = values.Keys.Union(_meta.Keys).ToDictionary(key => key, key => values.ContainsKey(key) ? values[key] : _meta[key]);
33+
_meta = values.Keys.Union(_meta.Keys).ToDictionary(key => key, key => values.TryGetValue(key, out object? value) ? value : _meta[key]);
3434
}
3535

3636
/// <inheritdoc />

0 commit comments

Comments
 (0)