blob: bb692116a423dac750405359b2755bb23d2a16f5 (
plain)
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
|
//-----------------------------------------------------------------------
// <copyright file="UriElement.cs" company="Outercurve Foundation, Scott Hanselman">
// Copyright (c) Outercurve Foundation, Scott Hanselman. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Xrds {
using System;
using System.Xml.XPath;
/// <summary>
/// The Uri element in an XRDS document.
/// </summary>
internal class UriElement : XrdsNode, IComparable<UriElement> {
/// <summary>
/// Initializes a new instance of the <see cref="UriElement"/> class.
/// </summary>
/// <param name="uriElement">The URI element.</param>
/// <param name="service">The service.</param>
public UriElement(XPathNavigator uriElement, ServiceElement service) :
base(uriElement, service) {
}
/// <summary>
/// Gets the priority.
/// </summary>
public int? Priority {
get {
XPathNavigator n = Node.SelectSingleNode("@priority", XmlNamespaceResolver);
return n != null ? n.ValueAsInt : (int?)null;
}
}
/// <summary>
/// Gets the URI.
/// </summary>
public Uri Uri {
get {
if (Node.Value != null) {
string value = Node.Value.Trim();
if (value.Length > 0) {
return new Uri(value);
}
}
return null;
}
}
/// <summary>
/// Gets the parent service.
/// </summary>
public ServiceElement Service {
get { return (ServiceElement)ParentNode; }
}
#region IComparable<UriElement> Members
/// <summary>
/// Compares the current object with another object of the same type.
/// </summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns>
/// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings:
/// Value
/// Meaning
/// Less than zero
/// This object is less than the <paramref name="other"/> parameter.
/// Zero
/// This object is equal to <paramref name="other"/>.
/// Greater than zero
/// This object is greater than <paramref name="other"/>.
/// </returns>
public int CompareTo(UriElement other) {
if (other == null) {
return -1;
}
int compare = this.Service.CompareTo(other.Service);
if (compare != 0) {
return compare;
}
if (this.Priority.HasValue && other.Priority.HasValue) {
return this.Priority.Value.CompareTo(other.Priority.Value);
} else {
if (this.Priority.HasValue) {
return -1;
} else if (other.Priority.HasValue) {
return 1;
} else {
return 0;
}
}
}
#endregion
}
}
|