/
AttrAttribute.cs
57 lines (48 loc) · 1.57 KB
/
AttrAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using JetBrains.Annotations;
namespace JsonApiDotNetCore.Resources.Annotations;
/// <summary>
/// Used to expose a property on a resource class as a JSON:API attribute (https://jsonapi.org/format/#document-resource-object-attributes).
/// </summary>
[PublicAPI]
[AttributeUsage(AttributeTargets.Property)]
public sealed class AttrAttribute : ResourceFieldAttribute
{
private AttrCapabilities? _capabilities;
internal bool HasExplicitCapabilities => _capabilities != null;
/// <summary>
/// The set of allowed capabilities on this attribute. When not explicitly set, the configured default set of capabilities is used.
/// </summary>
/// <example>
/// <code><![CDATA[
/// public class Author : Identifiable<long>
/// {
/// [Attr(Capabilities = AttrCapabilities.AllowFilter | AttrCapabilities.AllowSort)]
/// public string Name { get; set; } = null!;
/// }
/// ]]></code>
/// </example>
public AttrCapabilities Capabilities
{
get => _capabilities ?? default;
set => _capabilities = value;
}
/// <inheritdoc />
public override bool Equals(object? obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj is null || GetType() != obj.GetType())
{
return false;
}
var other = (AttrAttribute)obj;
return Capabilities == other.Capabilities && base.Equals(other);
}
/// <inheritdoc />
public override int GetHashCode()
{
return HashCode.Combine(Capabilities, base.GetHashCode());
}
}