@@ -5,6 +5,26 @@ namespace JsonApiDotNetCore.Models
5
5
{
6
6
public class AttrAttribute : Attribute
7
7
{
8
+ /// <summary>
9
+ /// Defines a public attribute exposed by the API
10
+ /// </summary>
11
+ ///
12
+ /// <param name="publicName">How this attribute is exposed through the API</param>
13
+ /// <param name="isImmutable">Prevent PATCH requests from updating the value</param>
14
+ /// <param name="isFilterable">Prevent filters on this attribute</param>
15
+ /// <param name="isSortable">Prevent this attribute from being sorted by</param>
16
+ ///
17
+ /// <example>
18
+ ///
19
+ /// <code>
20
+ /// public class Author : Identifiable
21
+ /// {
22
+ /// [Attr("name")]
23
+ /// public string Name { get; set; }
24
+ /// }
25
+ /// </code>
26
+ ///
27
+ /// </example>
8
28
public AttrAttribute ( string publicName , bool isImmutable = false , bool isFilterable = true , bool isSortable = true )
9
29
{
10
30
PublicAttributeName = publicName ;
@@ -20,20 +40,51 @@ internal AttrAttribute(string publicName, string internalName, bool isImmutable
20
40
IsImmutable = isImmutable ;
21
41
}
22
42
43
+ /// <summary>
44
+ /// How this attribute is exposed through the API
45
+ /// </summary>
23
46
public string PublicAttributeName { get ; }
47
+
48
+ /// <summary>
49
+ /// The internal property name this attribute belongs to.
50
+ /// </summary>
24
51
public string InternalAttributeName { get ; internal set ; }
52
+
53
+ /// <summary>
54
+ /// Prevents PATCH requests from updating the value.
55
+ /// </summary>
25
56
public bool IsImmutable { get ; }
57
+
58
+ /// <summary>
59
+ /// Whether or not this attribute can be filtered on via a query string filters.
60
+ /// Attempts to filter on an attribute with `IsFilterable == false` will return
61
+ /// an HTTP 400 response.
62
+ /// </summary>
26
63
public bool IsFilterable { get ; }
64
+
65
+ /// <summary>
66
+ /// Whether or not this attribute can be sorted on via a query string sort.
67
+ /// Attempts to filter on an attribute with `IsSortable == false` will return
68
+ /// an HTTP 400 response.
69
+ /// </summary>
27
70
public bool IsSortable { get ; }
28
71
72
+ /// <summary>
73
+ /// Get the value of the attribute for the given object.
74
+ /// Returns null if the attribute does not belong to the
75
+ /// provided object.
76
+ /// </summary>
29
77
public object GetValue ( object entity )
30
78
{
31
79
return entity
32
80
. GetType ( )
33
81
. GetProperty ( InternalAttributeName )
34
- . GetValue ( entity ) ;
82
+ ? . GetValue ( entity ) ;
35
83
}
36
84
85
+ /// <summary>
86
+ /// Sets the value of the attribute on the given object.
87
+ /// </summary>
37
88
public void SetValue ( object entity , object newValue )
38
89
{
39
90
var propertyInfo = entity
0 commit comments