-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathResourceTypeAttribute.cs
More file actions
39 lines (35 loc) · 1.23 KB
/
ResourceTypeAttribute.cs
File metadata and controls
39 lines (35 loc) · 1.23 KB
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
using System.Reflection;
using Newtonsoft.Json.Linq;
namespace JSONAPI.Core
{
/// <summary>
/// A ResourceTypeField representing an attribute on a resource object
/// </summary>
public class ResourceTypeAttribute : ResourceTypeField
{
private readonly IAttributeValueConverter _attributeValueConverter;
internal ResourceTypeAttribute(IAttributeValueConverter attributeValueConverter, PropertyInfo property, string jsonKey)
: base(property, jsonKey)
{
_attributeValueConverter = attributeValueConverter;
}
/// <summary>
/// Gets the json-formatted value of this attribute for the given resource
/// </summary>
/// <param name="resource"></param>
/// <returns></returns>
public JToken GetValue(object resource)
{
return _attributeValueConverter.GetValue(resource);
}
/// <summary>
/// Sets the value of this attribute for the resource
/// </summary>
/// <param name="resource"></param>
/// <param name="value"></param>
public void SetValue(object resource, JToken value)
{
_attributeValueConverter.SetValue(resource, value);
}
}
}