forked from NancyFx/Nancy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryWrapper.cs
More file actions
67 lines (61 loc) · 2.46 KB
/
Copy pathQueryWrapper.cs
File metadata and controls
67 lines (61 loc) · 2.46 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
namespace Nancy.Testing
{
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using CsQuery;
using CsQuery.Implementation;
public class QueryWrapper : IEnumerable<NodeWrapper>
{
private readonly CQ document;
/// <summary>
/// Initializes a new instance of the <see cref="QueryWrapper"/> class, using
/// the provided <paramref name="document"/>.
/// </summary>
/// <param name="document">The document that should be wrapped.</param>
public QueryWrapper(CQ document)
{
this.document = document;
}
/// <summary>
/// Gets elements from CSS3 selectors
/// </summary>
/// <param name="selector">CSS3 selector</param>
/// <returns>A <see cref="QueryWrapper"/> instance</returns>
public QueryWrapper this[string selector]
{
get
{
var newDocument = this.document.Selector == null
? this.document
: new CQ(this.document.RenderSelection());
return new QueryWrapper(newDocument[selector]);
}
}
/// <summary>
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>A <see cref="IEnumerator{T}"/> that can be used to iterate through the collection.</returns>
public IEnumerator<NodeWrapper> GetEnumerator()
{
return this.document.Select(x => new NodeWrapper(x as DomElement)).GetEnumerator();
}
/// <summary>
/// Returns an enumerator that iterates through a collection.
/// </summary>
/// <returns>An <see cref="IEnumerator"/> object that can be used to iterate through the collection.</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
/// <summary>
/// Performs an implicit conversion from <see cref="CQ"/> to <see cref="QueryWrapper"/>.
/// </summary>
/// <param name="document">The <see cref="CQ"/> that should be cast.</param>
/// <returns>An <see cref="QueryWrapper"/> instance, that contains the results of the cast.</returns>
public static implicit operator QueryWrapper(CQ document)
{
return new QueryWrapper(document);
}
}
}