File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
src/JsonApiDotNetCore/Resources Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments