-
Notifications
You must be signed in to change notification settings - Fork 146
/
Link.cs
66 lines (59 loc) · 2.18 KB
/
Link.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
58
59
60
61
62
63
64
65
66
using System;
using System.ComponentModel;
using Newtonsoft.Json;
namespace BeautifulRestApi.Models
{
public class Link
{
public const string GetMethod = "GET";
public const string PostMethod = "POST";
public const string DeleteMethod = "DELETE";
public static RouteLink To(string routeName, object routeValues = null)
=> new RouteLink
{
RouteName = routeName,
RouteValues = routeValues,
Method = GetMethod,
Relations = null
};
public static RouteLink ToCollection(string routeName, object routeValues = null)
=> new RouteLink
{
RouteName = routeName,
RouteValues = routeValues,
Method = GetMethod,
Relations = new string[] { Collection<Link>.CollectionRelation }
};
public static Link ToForm(
string routeName,
object routeValues = null,
string method = PostMethod,
params string[] relations)
=> new RouteLink
{
RouteName = routeName,
RouteValues = routeValues,
Method = method,
Relations = relations
};
/// <summary>
/// Gets or sets the link target (href).
/// </summary>
/// <value>The link target (href).</value>
[JsonProperty(Order = -4)]
public string Href { get; set; }
/// <summary>
/// Gets or sets the method used when following the link.
/// </summary>
/// <value>The method used when following the link.</value>
[JsonProperty(Order = -3, NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore)]
[DefaultValue(GetMethod)]
public string Method { get; set; }
/// <summary>
/// Gets or sets the optional link relations.
/// </summary>
/// <value>The link relations.</value>
[JsonProperty(Order = -2, PropertyName = "rel", NullValueHandling = NullValueHandling.Ignore)]
public string[] Relations { get; set; }
}
}