You've already forked linux-packaging-mono
Imported Upstream version 4.0.0~alpha1
Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
69
external/referencesource/System.ServiceModel/System/UriTemplateVariablePathSegment.cs
vendored
Normal file
69
external/referencesource/System.ServiceModel/System/UriTemplateVariablePathSegment.cs
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System
|
||||
{
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime;
|
||||
using System.Text;
|
||||
|
||||
class UriTemplateVariablePathSegment : UriTemplatePathSegment
|
||||
{
|
||||
readonly string varName;
|
||||
|
||||
public UriTemplateVariablePathSegment(string originalSegment, bool endsWithSlash, string varName)
|
||||
: base(originalSegment, UriTemplatePartType.Variable, endsWithSlash)
|
||||
{
|
||||
Fx.Assert(!string.IsNullOrEmpty(varName), "bad variable segment");
|
||||
this.varName = varName;
|
||||
}
|
||||
|
||||
public string VarName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.varName;
|
||||
}
|
||||
}
|
||||
public override void Bind(string[] values, ref int valueIndex, StringBuilder path)
|
||||
{
|
||||
Fx.Assert(valueIndex < values.Length, "Not enough values to bind");
|
||||
if (this.EndsWithSlash)
|
||||
{
|
||||
path.AppendFormat("{0}/", values[valueIndex++]);
|
||||
}
|
||||
else
|
||||
{
|
||||
path.Append(values[valueIndex++]);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
Fx.Assert("why would we ever call this?");
|
||||
return false;
|
||||
}
|
||||
if (!ignoreTrailingSlash && (this.EndsWithSlash != other.EndsWithSlash))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (other.Nature == UriTemplatePartType.Variable);
|
||||
}
|
||||
public override bool IsMatch(UriTemplateLiteralPathSegment segment, bool ignoreTrailingSlash)
|
||||
{
|
||||
if (!ignoreTrailingSlash && (this.EndsWithSlash != segment.EndsWithSlash))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (!segment.IsNullOrEmpty());
|
||||
}
|
||||
public override void Lookup(string segment, NameValueCollection boundParameters)
|
||||
{
|
||||
Fx.Assert(!string.IsNullOrEmpty(segment), "How can that be? Lookup is expected to be called after IsMatch");
|
||||
boundParameters.Add(this.varName, segment);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user