forked from jamietre/CsQuery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_StaticMethods.cs
More file actions
218 lines (187 loc) · 5.37 KB
/
Copy path_StaticMethods.cs
File metadata and controls
218 lines (187 loc) · 5.37 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;
using System.IO;
using System.Web;
using System.Web.Script.Serialization;
using CsQuery.ExtensionMethods.Internal;
using CsQuery.Utility;
using CsQuery.Engine;
using CsQuery.Web;
using CsQuery.Promises;
using CsQuery.HtmlParser;
using CsQuery.Implementation;
namespace CsQuery
{
public partial class CQ
{
#region CsQuery global options
/// <summary>
/// DEPRECATED. Please use CsQuery.Config.DomRenderingOptions.
/// </summary>
[Obsolete]
public static DomRenderingOptions DefaultDomRenderingOptions
{
get {
return Config.DomRenderingOptions;
}
set {
Config.DomRenderingOptions = value;
}
}
/// <summary>
/// DEPRECATED. Please use CsQuery.Config.DocType
/// </summary>
[Obsolete]
public static DocType DefaultDocType {
get
{
return Config.DocType;
}
set
{
Config.DocType = value;
}
}
#endregion
#region private properties
private static Browser _Browser;
#endregion
#region static utility methods
/// <summary>
/// Convert an object to JSON.
/// </summary>
///
/// <param name="json">
/// The obect to serialize.
/// </param>
///
/// <returns>
/// A JSON formatted string.
/// </returns>
public static string ToJSON(object json)
{
return Utility.JSON.ToJSON(json);
}
/// <summary>
/// Parse JSON into a typed object.
/// </summary>
///
/// <typeparam name="T">
/// The target type of the object to create.
/// </typeparam>
/// <param name="json">
/// The JSON string to deserialize.
/// </param>
///
/// <returns>
/// A new object of type T
/// </returns>
public static T ParseJSON<T>(string json)
{
return Utility.JSON.ParseJSON<T>(json);
}
/// <summary>
/// Parse a JSON string into an expando object, or a json value into a primitive type.
/// </summary>
///
/// <param name="json">
/// The JSON string to deserialize.
/// </param>
///
/// <returns>
/// A new object of type T
/// </returns>
public static object ParseJSON(string json)
{
return Utility.JSON.ParseJSON(json);
}
/// <summary>
/// Parse a JSON string into an expando object, or a json value into a primitive type.
/// </summary>
///
/// <param name="json">
/// The JSON string to deserialize.
/// </param>
/// <param name="type">
/// The type of object to create
/// </param>
///
/// <returns>
/// A new object of the specified type
/// </returns>
public static object ParseJSON(string json, Type type)
{
return Utility.JSON.ParseJSON(json, type);
}
/// <summary>
/// Convert a dictionary to a dynamic object. Use to get another expando object from a sub-
/// object of an expando object, e.g. as returned from JSON data.
/// </summary>
///
/// <param name="obj">
/// The object.
/// </param>
///
/// <returns>
/// obj as a JsObject.
/// </returns>
public static JsObject ToExpando(object obj)
{
JsObject result;
if (obj is IDictionary<string, object>)
{
result = Objects.Dict2Dynamic<JsObject>((IDictionary<string, object>)obj);
}
else
{
return Objects.ToExpando(obj);
}
return result;
}
/// <summary>
/// Converts an object to a dynamic object of type T.
/// </summary>
///
/// <typeparam name="T">
/// The type of object to create. This must be an IDynamicMetaObjectProvider that also implements
/// IDictionary<string,object>
/// </typeparam>
/// <param name="obj">
/// The object.
/// </param>
///
/// <returns>
/// A new object of type T.
/// </returns>
public static T ToDynamic<T>(object obj) where T : IDynamicMetaObjectProvider, IDictionary<string,object>,new()
{
if (obj is IDictionary<string, object>)
{
return Objects.Dict2Dynamic<T>((IDictionary<string, object>)obj);
}
else
{
return Objects.ToExpando<T>(obj);
}
}
/// <summary>
/// (Alpha) Provide simple user agent information.
/// </summary>
public static Browser Browser
{
get
{
if (_Browser == null)
{
_Browser = new Browser(HttpContext.Current);
}
return _Browser;
}
}
#endregion
}
}