forked from smartstore/SmartStoreNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouteInfo.cs
More file actions
133 lines (112 loc) · 3.1 KB
/
Copy pathRouteInfo.cs
File metadata and controls
133 lines (112 loc) · 3.1 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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Routing;
using Newtonsoft.Json;
namespace SmartStore
{
[JsonConverter(typeof(RouteInfoConverter))]
public class RouteInfo
{
public RouteInfo(RouteInfo cloneFrom)
: this(cloneFrom.Action, cloneFrom.Controller, new RouteValueDictionary(cloneFrom.RouteValues))
{
Guard.NotNull(cloneFrom, nameof(cloneFrom));
}
public RouteInfo(string action, object routeValues)
: this(action, null, routeValues)
{
}
public RouteInfo(string action, string controller, object routeValues)
: this(action, controller, new RouteValueDictionary(routeValues))
{
}
public RouteInfo(string action, IDictionary<string, object> routeValues)
: this(action, null, routeValues)
{
}
public RouteInfo(string action, string controller, IDictionary<string, object> routeValues)
: this(action, controller, new RouteValueDictionary(routeValues))
{
Guard.NotNull(routeValues, nameof(routeValues));
}
public RouteInfo(string action, RouteValueDictionary routeValues)
: this(action, null, routeValues)
{
}
[JsonConstructor]
public RouteInfo(string action, string controller, RouteValueDictionary routeValues)
{
Guard.NotEmpty(action, nameof(action));
Guard.NotNull(routeValues, nameof(routeValues));
this.Action = action;
this.Controller = controller;
this.RouteValues = routeValues;
}
public string Action
{
get;
private set;
}
public string Controller
{
get;
private set;
}
public RouteValueDictionary RouteValues
{
get;
private set;
}
}
#region JsonConverter
public class RouteInfoConverter : JsonConverter
{
public override bool CanWrite
{
get { return false; }
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof(RouteInfo);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
string action = null;
string controller = null;
RouteValueDictionary routeValues = null;
reader.Read();
while (reader.TokenType == JsonToken.PropertyName)
{
string a = reader.Value.ToString();
if (string.Equals(a, "Action", StringComparison.OrdinalIgnoreCase))
{
reader.Read();
action = serializer.Deserialize<string>(reader);
}
else if (string.Equals(a, "Controller", StringComparison.OrdinalIgnoreCase))
{
reader.Read();
controller = serializer.Deserialize<string>(reader);
}
else if (string.Equals(a, "RouteValues", StringComparison.OrdinalIgnoreCase))
{
reader.Read();
routeValues = serializer.Deserialize<RouteValueDictionary>(reader);
}
else
{
reader.Skip();
}
reader.Read();
}
var routeInfo = Activator.CreateInstance(objectType, new object[] { action, controller, routeValues });
return routeInfo;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotSupportedException();
}
}
#endregion
}