本文整理汇总了C#中MindTouch.Dream.XUri.GetSegments方法的典型用法代码示例。如果您正苦于以下问题:C# XUri.GetSegments方法的具体用法?C# XUri.GetSegments怎么用?C# XUri.GetSegments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MindTouch.Dream.XUri
的用法示例。
在下文中一共展示了XUri.GetSegments方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Remove
internal void Remove(XUri uri)
{
Remove(uri.GetSegments(UriPathFormat.Normalized), 0);
}
示例2: ParseFeatureSignature
//--- Class Methods ---
private static void ParseFeatureSignature(XUri baseUri, string signature, out string[] pathSegments, out KeyValuePair<int, string>[] paramNames, out int optional)
{
List<string> segments = new List<string>(baseUri.GetSegments(UriPathFormat.Normalized));
List<KeyValuePair<int, string>> names = new List<KeyValuePair<int, string>>();
optional = 0;
// normalize and remove any leading and trailing '/'
signature = signature.ToLowerInvariant().Trim();
if((signature.Length > 0) && (signature[0] == '/')) {
signature = signature.Substring(1);
}
if((signature.Length > 0) && (signature[signature.Length - 1] == '/')) {
signature = signature.Substring(0, signature.Length - 1);
}
if(signature.Length > 0) {
string[] parts = signature.Split('/');
// loop over all parts
for(int i = 0; i < parts.Length; ++i) {
// check if part is empty (this only happens for "//")
if(parts[i].Length == 0) {
// we found two slashes in a row; the next token MUST be the final token
if((i != (parts.Length - 2)) || (parts[i + 1] != "*")) {
throw new ArgumentException("invalid feature signature", signature);
}
optional = int.MaxValue;
break;
} else {
string part = parts[i].Trim();
if((part.Length >= 2) && (part[0] == '{') && (part[part.Length - 1] == '}')) {
// we have a path variable (e.g. /{foo}/)
if(optional != 0) {
throw new ArgumentException("invalid feature signature", signature);
}
segments.Add(SysUtil.NameTable.Add("*"));
names.Add(new KeyValuePair<int, string>(baseUri.Segments.Length + i, SysUtil.NameTable.Add(part.Substring(1, part.Length - 2))));
} else if(part == "*") {
// we have a path wildcard (e.g. /*/)
if(optional != 0) {
throw new ArgumentException("invalid feature signature", signature);
}
segments.Add(SysUtil.NameTable.Add(part));
names.Add(new KeyValuePair<int, string>(baseUri.Segments.Length + i, SysUtil.NameTable.Add(i.ToInvariantString())));
} else if(part == "?") {
// we have an optional path (e.g. /?/)
++optional;
segments.Add(SysUtil.NameTable.Add(part));
} else {
// we have a path constant (e.g. /foo/)
if(optional != 0) {
throw new ArgumentException("invalid feature signature", signature);
}
segments.Add(SysUtil.NameTable.Add(part));
}
}
}
}
pathSegments = segments.ToArray();
paramNames = names.ToArray();
}
示例3: Find
internal List<DreamFeature> Find(XUri uri)
{
return Find(uri.GetSegments(UriPathFormat.Normalized), 0);
}