Skip to content

Commit 1ba05e2

Browse files
author
Bart Koelman
committed
Extract constant
1 parent 267221a commit 1ba05e2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/JsonApiDotNetCore/Resources/IdentifiableExtensions.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ namespace JsonApiDotNetCore.Resources
66
{
77
internal static class IdentifiableExtensions
88
{
9+
private const string IdPropertyName = nameof(Identifiable<object>.Id);
10+
911
public static object GetTypedId(this IIdentifiable identifiable)
1012
{
1113
ArgumentGuard.NotNull(identifiable, nameof(identifiable));
1214

13-
PropertyInfo? property = identifiable.GetType().GetProperty(nameof(Identifiable<object>.Id));
15+
PropertyInfo? property = identifiable.GetType().GetProperty(IdPropertyName);
1416

1517
if (property == null)
1618
{
17-
throw new InvalidOperationException($"Resource of type '{identifiable.GetType()}' does not have an 'Id' property.");
19+
throw new InvalidOperationException($"Resource of type '{identifiable.GetType()}' does not contain a property named '{IdPropertyName}'.");
1820
}
1921

2022
object? propertyValue = property.GetValue(identifiable);
@@ -26,7 +28,7 @@ public static object GetTypedId(this IIdentifiable identifiable)
2628

2729
if (Equals(propertyValue, defaultValue))
2830
{
29-
throw new InvalidOperationException($"Property '{identifiable.GetType().Name}.{nameof(Identifiable<object>.Id)}' should " +
31+
throw new InvalidOperationException($"Property '{identifiable.GetType().Name}.{IdPropertyName}' should " +
3032
$"have been assigned at this point, but it contains its default {property.PropertyType.Name} value '{propertyValue}'.");
3133
}
3234
}

0 commit comments

Comments
 (0)