forked from ahzf/CsQuery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptRef.cs
More file actions
206 lines (173 loc) · 5.36 KB
/
Copy pathScriptRef.cs
File metadata and controls
206 lines (173 loc) · 5.36 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CsQuery.ExtensionMethods.Internal;
namespace CsQuery.Mvc.ClientScript
{
/// <summary>
/// A class representing a reference to a client script.
/// </summary>
public class ScriptRef
{
/// <summary>
/// Default constructor.
/// </summary>
public ScriptRef()
{
Dependencies = new List<ScriptRef>();
}
private string _Path;
/// <summary>
/// Return the relative path root for this file, e.g. the path excluding the file name.
/// </summary>
public string RelativePathRoot
{
get
{
return Path.BeforeLast("/")+"/";
}
}
/// <summary>
/// Virtual path to the dependency
/// </summary>
public string Path
{
get
{
return _Path;
}
set
{
_Path = value.Replace("\\", "/");
}
}
/// <summary>
/// Gets or sets a value indicating whether the dependency path has been resolved.
/// </summary>
public bool Resolved { get; protected set; }
/// <summary>
/// A has that uniquely identifies the contents to prevent browser caching when they have changed
/// </summary>
public string ScriptHash { get; set; }
/// <summary>
/// When true, the script should not be combined but always loaded individually.
/// </summary>
public bool NoCombine { get; set; }
/// <summary>
/// Dependencies for this ScriptRef
/// </summary>
///
/// <value>
/// The dependencies.
/// </value>
public List<ScriptRef> Dependencies { get; protected set; }
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
///
/// <returns>
/// A hash code for the current <see cref="T:System.Object" />.
/// </returns>
public override int GetHashCode()
{
return Path != null ? Path.GetHashCode() : 0;
}
/// <summary>
/// Determines whether the specified <see cref="T:System.Object" /> is equal to the current
/// <see cref="T:System.Object" />.
/// </summary>
///
/// <param name="obj">
/// The object to compare with the current object.
/// </param>
///
/// <returns>
/// true if the specified <see cref="T:System.Object" /> is equal to the current
/// <see cref="T:System.Object" />; otherwise, false.
/// </returns>
public override bool Equals(object obj)
{
ScriptRef other = obj as ScriptRef;
return other != null &&
Path == other.Path;
}
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
///
/// <returns>
/// A string that represents the current object.
/// </returns>
public override string ToString()
{
return "[" + Path + "]: \"" + Path + "\"";
}
/// <summary>
/// Updates this script reference's details from another equivalent reference. (Will fail if they do not have the same name).
/// </summary>
///
/// <param name="other">
/// The other script reference.
/// </param>
public void UpdateFrom(ScriptRef other)
{
if (other == null || other.Path != Path)
{
throw new InvalidOperationException("The other script reference must have the same name as this one.");
}
ScriptHash = other.ScriptHash;
Resolved = other.Resolved;
Dependencies = new List<ScriptRef>(other.Dependencies);
Path = other.Path;
}
/// <summary>
/// Equality operator.
/// </summary>
///
/// <param name="x">
/// The first instance to compare.
/// </param>
/// <param name="y">
/// The second instance to compare.
/// </param>
///
/// <returns>
/// true if the parameters are considered equivalent.
/// </returns>
public static bool operator ==(ScriptRef x, ScriptRef y)
{
return AreEqual(x, y);
}
/// <summary>
/// Inequality operator.
/// </summary>
///
/// <param name="x">
/// The first instance to compare.
/// </param>
/// <param name="y">
/// The second instance to compare.
/// </param>
///
/// <returns>
/// true if the parameters are not considered equivalent.
/// </returns>
public static bool operator !=(ScriptRef x, ScriptRef y)
{
return !AreEqual(x,y);
}
private static bool AreEqual(ScriptRef x, ScriptRef y) {
bool xIsNull = ReferenceEquals(x, null);
bool yIsNull = ReferenceEquals(y, null);
if (xIsNull != yIsNull)
{
return false;
}
else
{
return xIsNull || x.Equals(y);
}
}
}
}