File tree 1 file changed +5
-3
lines changed
src/JsonApiDotNetCore/Resources
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -6,15 +6,17 @@ namespace JsonApiDotNetCore.Resources
6
6
{
7
7
internal static class IdentifiableExtensions
8
8
{
9
+ private const string IdPropertyName = nameof ( Identifiable < object > . Id ) ;
10
+
9
11
public static object GetTypedId ( this IIdentifiable identifiable )
10
12
{
11
13
ArgumentGuard . NotNull ( identifiable , nameof ( identifiable ) ) ;
12
14
13
- PropertyInfo ? property = identifiable . GetType ( ) . GetProperty ( nameof ( Identifiable < object > . Id ) ) ;
15
+ PropertyInfo ? property = identifiable . GetType ( ) . GetProperty ( IdPropertyName ) ;
14
16
15
17
if ( property == null )
16
18
{
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 } ' .") ;
18
20
}
19
21
20
22
object ? propertyValue = property . GetValue ( identifiable ) ;
@@ -26,7 +28,7 @@ public static object GetTypedId(this IIdentifiable identifiable)
26
28
27
29
if ( Equals ( propertyValue , defaultValue ) )
28
30
{
29
- throw new InvalidOperationException ( $ "Property '{ identifiable . GetType ( ) . Name } .{ nameof ( Identifiable < object > . Id ) } ' should " +
31
+ throw new InvalidOperationException ( $ "Property '{ identifiable . GetType ( ) . Name } .{ IdPropertyName } ' should " +
30
32
$ "have been assigned at this point, but it contains its default { property . PropertyType . Name } value '{ propertyValue } '.") ;
31
33
}
32
34
}
You can’t perform that action at this time.
0 commit comments