Skip to content

Commit 9b544c8

Browse files
author
Bart Koelman
committed
1 parent 2adff3c commit 9b544c8

34 files changed

+88
-57
lines changed

src/Examples/GettingStarted/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace GettingStarted
55
{
6-
public class Program
6+
public static class Program
77
{
88
public static void Main(string[] args)
99
{

src/Examples/JsonApiDotNetCoreExample/Definitions/TagHooksDefinition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public class TagHooksDefinition : ResourceHooksDefinition<Tag>
1111
{
1212
public TagHooksDefinition(IResourceGraph resourceGraph) : base(resourceGraph) { }
1313

14-
public override IEnumerable<Tag> BeforeCreate(IResourceHashSet<Tag> affected, ResourcePipeline pipeline)
14+
public override IEnumerable<Tag> BeforeCreate(IResourceHashSet<Tag> resources, ResourcePipeline pipeline)
1515
{
16-
return base.BeforeCreate(affected, pipeline);
16+
return base.BeforeCreate(resources, pipeline);
1717
}
1818

1919
public override IEnumerable<Tag> OnReturn(HashSet<Tag> resources, ResourcePipeline pipeline)

src/Examples/JsonApiDotNetCoreExample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace JsonApiDotNetCoreExample
66
{
7-
public class Program
7+
public static class Program
88
{
99
public static void Main(string[] args)
1010
{

src/Examples/MultiDbContextExample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace MultiDbContextExample
55
{
6-
public class Program
6+
public static class Program
77
{
88
public static void Main(string[] args)
99
{

src/Examples/NoEntityFrameworkExample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace NoEntityFrameworkExample
55
{
6-
public class Program
6+
public static class Program
77
{
88
public static void Main(string[] args)
99
{

src/Examples/ReportsExample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace ReportsExample
55
{
6-
public class Program
6+
public static class Program
77
{
88
public static void Main(string[] args)
99
{

src/JsonApiDotNetCore/AtomicOperations/LocalIdValidator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public LocalIdValidator(ILocalIdTracker localIdTracker, IResourceContextProvider
2525

2626
public void Validate(IEnumerable<OperationContainer> operations)
2727
{
28+
ArgumentGuard.NotNull(operations, nameof(operations));
29+
2830
_localIdTracker.Reset();
2931

3032
int operationIndex = 0;

src/JsonApiDotNetCore/Hooks/Internal/Discovery/LoadDatabaseValuesAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ public sealed class LoadDatabaseValuesAttribute : Attribute
77
{
88
public bool Value { get; }
99

10-
public LoadDatabaseValuesAttribute(bool mode = true)
10+
public LoadDatabaseValuesAttribute(bool value = true)
1111
{
12-
Value = mode;
12+
Value = value;
1313
}
1414
}
1515
}

src/JsonApiDotNetCore/Hooks/Internal/Execution/DiffableResourceHashSet.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public IEnumerable<ResourceDiffPair<TResource>> GetDiffs()
5757
/// <inheritdoc />
5858
public new HashSet<TResource> GetAffected(Expression<Func<TResource, object>> navigationAction)
5959
{
60+
ArgumentGuard.NotNull(navigationAction, nameof(navigationAction));
61+
6062
var propertyInfo = TypeHelper.ParseNavigationExpression(navigationAction);
6163
var propertyType = propertyInfo.PropertyType;
6264
if (TypeHelper.IsOrImplementsInterface(propertyType, typeof(IEnumerable)))

src/JsonApiDotNetCore/Hooks/Internal/Execution/IRelationshipGetters.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public interface IRelationshipGetters<TLeftResource> where TLeftResource : class
1616
/// </summary>
1717
Dictionary<RelationshipAttribute, HashSet<TLeftResource>> GetByRelationship<TRightResource>() where TRightResource : class, IIdentifiable;
1818
/// <summary>
19-
/// Gets a dictionary of all resources that have an affected relationship to type <paramref name="relatedResourceType"/>
19+
/// Gets a dictionary of all resources that have an affected relationship to type <paramref name="resourceType"/>
2020
/// </summary>
21-
Dictionary<RelationshipAttribute, HashSet<TLeftResource>> GetByRelationship(Type relatedResourceType);
21+
Dictionary<RelationshipAttribute, HashSet<TLeftResource>> GetByRelationship(Type resourceType);
2222
/// <summary>
2323
/// Gets a collection of all the resources for the property within <paramref name="navigationAction"/>
2424
/// has been affected by the request

src/JsonApiDotNetCore/Hooks/Internal/Execution/RelationshipsDictionary.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship<T
3737
}
3838

3939
/// <inheritdoc />
40-
public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship(Type relatedType)
40+
public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship(Type resourceType)
4141
{
42-
return this.Where(p => p.Key.RightType == relatedType).ToDictionary(p => p.Key, p => p.Value);
42+
return this.Where(p => p.Key.RightType == resourceType).ToDictionary(p => p.Key, p => p.Value);
4343
}
4444

4545
/// <inheritdoc />
4646
public HashSet<TResource> GetAffected(Expression<Func<TResource, object>> navigationAction)
4747
{
48+
ArgumentGuard.NotNull(navigationAction, nameof(navigationAction));
49+
4850
var property = TypeHelper.ParseNavigationExpression(navigationAction);
4951
return this.Where(p => p.Key.Property.Name == property.Name).Select(p => p.Value).SingleOrDefault();
5052
}

src/JsonApiDotNetCore/Hooks/Internal/Execution/ResourceHashSet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ internal ResourceHashSet(IEnumerable resources,
3737

3838

3939
/// <inheritdoc />
40-
public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship(Type leftType)
40+
public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship(Type resourceType)
4141
{
42-
return _relationships.GetByRelationship(leftType);
42+
return _relationships.GetByRelationship(resourceType);
4343
}
4444

4545
/// <inheritdoc />

src/JsonApiDotNetCore/Hooks/Internal/ResourceHookExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ private void ValidateHookResponse<T>(IEnumerable<T> returnedList, ResourcePipeli
405405
{
406406
if (pipeline == ResourcePipeline.GetSingle && returnedList.Count() > 1)
407407
{
408-
throw new ApplicationException("The returned collection from this hook may contain at most one item in the case of the " +
408+
throw new InvalidOperationException("The returned collection from this hook may contain at most one item in the case of the " +
409409
pipeline.ToString("G") + " pipeline");
410410
}
411411
}

src/JsonApiDotNetCore/Middleware/TraceLogWriter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ private static string FormatMessage(string memberName, object parameters)
4242

4343
builder.Append("Entering ");
4444
builder.Append(memberName);
45-
builder.Append("(");
45+
builder.Append('(');
4646
WriteProperties(builder, parameters);
47-
builder.Append(")");
47+
builder.Append(')');
4848

4949
return builder.ToString();
5050
}
@@ -82,9 +82,9 @@ private static void WriteProperty(StringBuilder builder, PropertyInfo property,
8282
}
8383
else if (value is string stringValue)
8484
{
85-
builder.Append("\"");
85+
builder.Append('"');
8686
builder.Append(stringValue);
87-
builder.Append("\"");
87+
builder.Append('"');
8888
}
8989
else
9090
{

src/JsonApiDotNetCore/Queries/Expressions/SparseFieldTableExpression.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ public override string ToString()
3838
{
3939
if (builder.Length > 0)
4040
{
41-
builder.Append(",");
41+
builder.Append(',');
4242
}
4343

4444
builder.Append(resource.PublicName);
45-
builder.Append("(");
45+
builder.Append('(');
4646
builder.Append(fields);
47-
builder.Append(")");
47+
builder.Append(')');
4848
}
4949

5050
return builder.ToString();

src/JsonApiDotNetCore/Queries/Internal/QueryLayerComposer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ public QueryLayer ComposeForUpdate<TId>(TId id, ResourceContext primaryResource)
342342
/// <inheritdoc />
343343
public IEnumerable<(QueryLayer, RelationshipAttribute)> ComposeForGetTargetedSecondaryResourceIds(IIdentifiable primaryResource)
344344
{
345+
ArgumentGuard.NotNull(primaryResource, nameof(primaryResource));
346+
345347
foreach (var relationship in _targetedFields.Relationships)
346348
{
347349
object rightValue = relationship.GetValue(primaryResource);
@@ -358,6 +360,9 @@ public QueryLayer ComposeForUpdate<TId>(TId id, ResourceContext primaryResource)
358360
/// <inheritdoc />
359361
public QueryLayer ComposeForGetRelationshipRightIds(RelationshipAttribute relationship, ICollection<IIdentifiable> rightResourceIds)
360362
{
363+
ArgumentGuard.NotNull(relationship, nameof(relationship));
364+
ArgumentGuard.NotNull(rightResourceIds, nameof(rightResourceIds));
365+
361366
var rightResourceContext = _resourceContextProvider.GetResourceContext(relationship.RightType);
362367
var rightIdAttribute = GetIdAttribute(rightResourceContext);
363368

@@ -380,6 +385,9 @@ public QueryLayer ComposeForGetRelationshipRightIds(RelationshipAttribute relati
380385
/// <inheritdoc />
381386
public QueryLayer ComposeForHasMany<TId>(HasManyAttribute hasManyRelationship, TId leftId, ICollection<IIdentifiable> rightResourceIds)
382387
{
388+
ArgumentGuard.NotNull(hasManyRelationship, nameof(hasManyRelationship));
389+
ArgumentGuard.NotNull(rightResourceIds, nameof(rightResourceIds));
390+
383391
var leftResourceContext = _resourceContextProvider.GetResourceContext(hasManyRelationship.LeftType);
384392
var leftIdAttribute = GetIdAttribute(leftResourceContext);
385393

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public override Expression VisitCount(CountExpression expression, TArgument argu
2929
var propertyExpression = TryGetCollectionCount(collectionExpression);
3030
if (propertyExpression == null)
3131
{
32-
throw new Exception($"Field '{expression.TargetCollection}' must be a collection.");
32+
throw new InvalidOperationException($"Field '{expression.TargetCollection}' must be a collection.");
3333
}
3434

3535
return propertyExpression;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private Expression CreateCollectionInitializer(LambdaScope lambdaScope, Property
194194

195195
if (typedCollectionConstructor == null)
196196
{
197-
throw new Exception(
197+
throw new InvalidOperationException(
198198
$"Constructor on '{typedCollection.Name}' that accepts '{enumerableOfElementType.Name}' not found.");
199199
}
200200

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public override Expression VisitCollectionNotEmpty(CollectionNotEmptyExpression
5555

5656
if (elementType == null)
5757
{
58-
throw new Exception("Expression must be a collection.");
58+
throw new InvalidOperationException("Expression must be a collection.");
5959
}
6060

6161
return AnyExtensionMethodCall(elementType, property);
@@ -75,7 +75,7 @@ public override Expression VisitMatchText(MatchTextExpression expression, Type a
7575

7676
if (property.Type != typeof(string))
7777
{
78-
throw new Exception("Expression must be a string.");
78+
throw new InvalidOperationException("Expression must be a string.");
7979
}
8080

8181
Expression text = Visit(expression.TextValue, property.Type);

src/JsonApiDotNetCore/Queries/Internal/SparseFieldSetCache.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public IReadOnlyCollection<AttrAttribute> GetIdAttributeSetForRelationshipQuery(
106106

107107
public IReadOnlyCollection<ResourceFieldAttribute> GetSparseFieldSetForSerializer(ResourceContext resourceContext)
108108
{
109+
ArgumentGuard.NotNull(resourceContext, nameof(resourceContext));
110+
109111
if (!_visitedTable.ContainsKey(resourceContext))
110112
{
111113
var inputFields = _lazySourceTable.Value.ContainsKey(resourceContext)

src/JsonApiDotNetCore/QueryStrings/Internal/FilterQueryStringParameterReader.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,30 @@ public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttr
5858
/// <inheritdoc />
5959
public virtual bool CanRead(string parameterName)
6060
{
61+
ArgumentGuard.NotNull(parameterName, nameof(parameterName));
62+
6163
var isNested = parameterName.StartsWith("filter[", StringComparison.Ordinal) && parameterName.EndsWith("]", StringComparison.Ordinal);
6264
return parameterName == "filter" || isNested;
6365
}
6466

6567
/// <inheritdoc />
66-
public virtual void Read(string parameterName, StringValues parameterValues)
68+
public virtual void Read(string parameterName, StringValues parameterValue)
6769
{
6870
_lastParameterName = parameterName;
6971

70-
foreach (string parameterValue in ExtractParameterValues(parameterName, parameterValues))
72+
foreach (string value in ExtractParameterValues(parameterValue))
7173
{
72-
ReadSingleValue(parameterName, parameterValue);
74+
ReadSingleValue(parameterName, value);
7375
}
7476
}
7577

76-
private IEnumerable<string> ExtractParameterValues(string parameterName, StringValues parameterValues)
78+
private IEnumerable<string> ExtractParameterValues(StringValues parameterValues)
7779
{
7880
foreach (string parameterValue in parameterValues)
7981
{
8082
if (_options.EnableLegacyFilterNotation)
8183
{
82-
foreach (string condition in LegacyConverter.ExtractConditions(parameterName, parameterValue))
84+
foreach (string condition in LegacyConverter.ExtractConditions(parameterValue))
8385
{
8486
yield return condition;
8587
}

src/JsonApiDotNetCore/QueryStrings/Internal/LegacyFilterNotationConverter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ public sealed class LegacyFilterNotationConverter
2525
["like:"] = Keywords.Contains
2626
};
2727

28-
public IEnumerable<string> ExtractConditions(string parameterName, string parameterValue)
28+
public IEnumerable<string> ExtractConditions(string parameterValue)
2929
{
30+
ArgumentGuard.NotNull(parameterValue, nameof(parameterValue));
31+
3032
if (parameterValue.StartsWith(ExpressionPrefix, StringComparison.Ordinal) ||
3133
parameterValue.StartsWith(InPrefix, StringComparison.Ordinal) ||
3234
parameterValue.StartsWith(NotInPrefix, StringComparison.Ordinal))

src/JsonApiDotNetCore/QueryStrings/Internal/SortQueryStringParameterReader.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttr
4747
/// <inheritdoc />
4848
public virtual bool CanRead(string parameterName)
4949
{
50+
ArgumentGuard.NotNull(parameterName, nameof(parameterName));
51+
5052
var isNested = parameterName.StartsWith("sort[", StringComparison.Ordinal) && parameterName.EndsWith("]", StringComparison.Ordinal);
5153
return parameterName == "sort" || isNested;
5254
}

src/JsonApiDotNetCore/QueryStrings/Internal/SparseFieldSetQueryStringParameterReader.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttr
4848
/// <inheritdoc />
4949
public virtual bool CanRead(string parameterName)
5050
{
51+
ArgumentGuard.NotNull(parameterName, nameof(parameterName));
52+
5153
return parameterName.StartsWith("fields[", StringComparison.Ordinal) && parameterName.EndsWith("]", StringComparison.Ordinal);
5254
}
5355

src/JsonApiDotNetCore/Serialization/Building/LinkBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ private string GetSelfTopLevelLink(ResourceContext resourceContext, Action<Dicti
112112
{
113113
var builder = new StringBuilder();
114114
builder.Append(_request.BasePath);
115-
builder.Append("/");
115+
builder.Append('/');
116116
builder.Append(resourceContext.PublicName);
117117

118118
if (_request.PrimaryId != null)
119119
{
120-
builder.Append("/");
120+
builder.Append('/');
121121
builder.Append(_request.PrimaryId);
122122
}
123123

@@ -128,7 +128,7 @@ private string GetSelfTopLevelLink(ResourceContext resourceContext, Action<Dicti
128128

129129
if (_request.Relationship != null)
130130
{
131-
builder.Append("/");
131+
builder.Append('/');
132132
builder.Append(_request.Relationship.PublicName);
133133
}
134134

src/JsonApiDotNetCore/Serialization/Client/Internal/IRequestSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public interface IRequestSerializer
2828
/// You can use <see cref="IResourceGraph.GetAttributes{TResource}"/>
2929
/// to conveniently access the desired <see cref="AttrAttribute"/> instances.
3030
/// </summary>
31-
public IReadOnlyCollection<AttrAttribute> AttributesToSerialize { set; }
31+
public IReadOnlyCollection<AttrAttribute> AttributesToSerialize { get; set; }
3232

3333
/// <summary>
3434
/// Sets the relationships that will be included in the serialized request body.
3535
/// You can use <see cref="IResourceGraph.GetRelationships"/>
3636
/// to conveniently access the desired <see cref="RelationshipAttribute"/> instances.
3737
/// </summary>
38-
public IReadOnlyCollection<RelationshipAttribute> RelationshipsToSerialize { set; }
38+
public IReadOnlyCollection<RelationshipAttribute> RelationshipsToSerialize { get; set; }
3939
}
4040
}

src/JsonApiDotNetCore/Serialization/Client/Internal/RequestSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ public string Serialize(IReadOnlyCollection<IIdentifiable> resources)
6969
}
7070

7171
/// <inheritdoc />
72-
public IReadOnlyCollection<AttrAttribute> AttributesToSerialize { private get; set; }
72+
public IReadOnlyCollection<AttrAttribute> AttributesToSerialize { get; set; }
7373

7474
/// <inheritdoc />
75-
public IReadOnlyCollection<RelationshipAttribute> RelationshipsToSerialize { private get; set; }
75+
public IReadOnlyCollection<RelationshipAttribute> RelationshipsToSerialize { get; set; }
7676

7777
/// <summary>
7878
/// By default, the client serializer includes all attributes in the result,

src/JsonApiDotNetCore/Serialization/Objects/ResourceIdentifierObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected static void WriteMember(StringBuilder builder, string memberName, stri
4343
builder.Append(memberName);
4444
builder.Append("=\"");
4545
builder.Append(memberValue);
46-
builder.Append("\"");
46+
builder.Append('"');
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)