1
+ using System ;
2
+
1
3
namespace JsonApiDotNetCore . Models
2
4
{
3
5
public class HasOneAttribute : RelationshipAttribute
@@ -7,10 +9,9 @@ public class HasOneAttribute : RelationshipAttribute
7
9
/// </summary>
8
10
///
9
11
/// <param name="publicName">The relationship name as exposed by the API</param>
10
- /// <param name="internalName">The relationship name as defined in the entity layer, if not provided defaults to the variable name</param>
11
12
/// <param name="documentLinks">Which links are available. Defaults to <see cref="Link.All"/></param>
12
13
/// <param name="canInclude">Whether or not this relationship can be included using the <c>?include=public-name</c> query string</param>
13
- /// <param name="withForiegnKey ">The foreign key property name. Defaults to <c>"{RelationshipName}Id"</c></param>
14
+ /// <param name="withForeignKey ">The foreign key property name. Defaults to <c>"{RelationshipName}Id"</c></param>
14
15
///
15
16
/// <example>
16
17
/// Using an alternative foreign key:
@@ -25,17 +26,16 @@ public class HasOneAttribute : RelationshipAttribute
25
26
/// </code>
26
27
///
27
28
/// </example>
28
- public HasOneAttribute ( string publicName , string internalName = null , Link documentLinks = Link . All ,
29
- bool canInclude = true , string withForiegnKey = null )
30
- : base ( publicName , internalName , documentLinks , canInclude )
29
+ public HasOneAttribute ( string publicName , Link documentLinks = Link . All , bool canInclude = true , string withForeignKey = null )
30
+ : base ( publicName , documentLinks , canInclude )
31
31
{
32
- _explicitIdentifiablePropertyName = withForiegnKey ;
32
+ _explicitIdentifiablePropertyName = withForeignKey ;
33
33
}
34
34
35
35
private readonly string _explicitIdentifiablePropertyName ;
36
36
37
37
/// <summary>
38
- /// The independent entity identifier.
38
+ /// The independent resource identifier.
39
39
/// </summary>
40
40
public string IdentifiablePropertyName => string . IsNullOrWhiteSpace ( _explicitIdentifiablePropertyName )
41
41
? $ "{ InternalRelationshipName } Id"
@@ -44,19 +44,19 @@ public HasOneAttribute(string publicName, string internalName = null, Link docum
44
44
/// <summary>
45
45
/// Sets the value of the property identified by this attribute
46
46
/// </summary>
47
- /// <param name="entity ">The target object</param>
47
+ /// <param name="resource ">The target object</param>
48
48
/// <param name="newValue">The new property value</param>
49
- public override void SetValue ( object entity , object newValue )
49
+ public override void SetValue ( object resource , object newValue )
50
50
{
51
51
var propertyName = ( newValue ? . GetType ( ) == Type )
52
52
? InternalRelationshipName
53
53
: IdentifiablePropertyName ;
54
54
55
- var propertyInfo = entity
55
+ var propertyInfo = resource
56
56
. GetType ( )
57
57
. GetProperty ( propertyName ) ;
58
58
59
- propertyInfo . SetValue ( entity , newValue ) ;
59
+ propertyInfo . SetValue ( resource , newValue ) ;
60
60
}
61
61
62
62
// HACK: this will likely require boxing
@@ -65,16 +65,16 @@ public override void SetValue(object entity, object newValue)
65
65
/// Gets the value of the independent identifier (e.g. Article.AuthorId)
66
66
/// </summary>
67
67
///
68
- /// <param name="entity ">
68
+ /// <param name="resource ">
69
69
/// An instance of dependent resource
70
70
/// </param>
71
71
///
72
72
/// <returns>
73
73
/// The property value or null if the property does not exist on the model.
74
74
/// </returns>
75
- internal object GetIdentifiablePropertyValue ( object entity ) => entity
75
+ internal object GetIdentifiablePropertyValue ( object resource ) => resource
76
76
. GetType ( )
77
77
. GetProperty ( IdentifiablePropertyName )
78
- ? . GetValue ( entity ) ;
78
+ ? . GetValue ( resource ) ;
79
79
}
80
80
}
0 commit comments