本文整理汇总了C#中System.UriTemplate.BindByName方法的典型用法代码示例。如果您正苦于以下问题:C# UriTemplate.BindByName方法的具体用法?C# UriTemplate.BindByName怎么用?C# UriTemplate.BindByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.UriTemplate
的用法示例。
在下文中一共展示了UriTemplate.BindByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildUriString
public string BuildUriString(NancyContext context, string routeName, dynamic parameters)
{
var baseUri = new Uri(context.Request.BaseUri().TrimEnd('/'));
var pathTemplate = AllRoutes.Single(r => r.Name == routeName).Path;
var uriTemplate = new UriTemplate(pathTemplate, true);
return uriTemplate.BindByName(baseUri, ToDictionary(parameters ?? new {})).ToString();
}
示例2: TestCompoundFragmentExpansionAssociativeMapVariable
public void TestCompoundFragmentExpansionAssociativeMapVariable()
{
string template = "{#keys*}";
UriTemplate uriTemplate = new UriTemplate(template);
Uri uri = uriTemplate.BindByName(variables);
string[] allowed =
{
"#comma=,,dot=.,semi=;",
"#comma=,,semi=;,dot=.",
"#dot=.,comma=,,semi=;",
"#dot=.,semi=;,comma=,",
"#semi=;,comma=,,dot=.",
"#semi=;,dot=.,comma=,"
};
CollectionAssert.Contains(allowed, uri.ToString());
UriTemplateMatch match = uriTemplate.Match(uri, new[] { "list" }, new[] { "keys" });
Assert.IsNotNull(match);
CollectionAssert.AreEqual((ICollection)variables["keys"], (ICollection)match.Bindings["keys"].Value);
match = uriTemplate.Match(uri, requiredVariables, new[] { "list" }, new[] { "keys" });
Assert.IsNotNull(match);
CollectionAssert.AreEqual((ICollection)variables["keys"], (ICollection)match.Bindings["keys"].Value);
}
示例3: BuildUriString
public string BuildUriString(string prefix, string template, dynamic parameters)
{
var newBaseUri = new Uri(baseUri.TrimEnd('/') + prefix);
var uriTemplate = new UriTemplate(template, true);
return uriTemplate.BindByName(newBaseUri, ToDictionary(parameters ?? new {})).ToString();
}
示例4: TestEmptyTemplate
public void TestEmptyTemplate()
{
string template = string.Empty;
UriTemplate uriTemplate = new UriTemplate(template);
Uri uri = uriTemplate.BindByName(variables);
Assert.AreEqual(string.Empty, uri.ToString());
UriTemplateMatch match = uriTemplate.Match(uri);
Assert.IsNotNull(match);
Assert.AreEqual(0, match.Bindings.Count);
}
示例5: BindTemplate
private static Uri BindTemplate(Uri baseUri, UriTemplate template, object parameters = null)
{
if (parameters == null)
{
Dictionary<string, string> emptyParameters = new Dictionary<string, string>();
return template.BindByName(baseUri, emptyParameters);
}
else if (parameters is IDictionary<string, string>)
{
return template.BindByName(baseUri, (IDictionary<string, string>)parameters);
}
else if (parameters is NameValueCollection)
{
return template.BindByName(baseUri, (NameValueCollection)parameters);
}
else
{
Dictionary<string, string> parameterDictionary = DictionaryConverter.ConvertObjectPropertiesToDictionary(parameters);
return template.BindByName(baseUri, parameterDictionary);
}
}
示例6: Experiment
public void Experiment()
{
var template = new UriTemplate("devices/{deviceId}/messages/outbound/{*subTopic}");
var baseUri = new Uri("http://whatever");
Uri bound = template.BindByName(baseUri, new Dictionary<string, string>
{
{ "deviceId", "VINno" },
{ "SubTopic", "toptop/toptoptop" },
});
var t2 = new UriTemplate("devices/{deviceId}/messages/log/{level=info}/{subject=n%2Fa}", true);
UriTemplateMatch match = t2.Match(baseUri, new Uri("http://whatever/devices/VINno/messages/log", UriKind.Absolute));
}
示例7: Main
public static void Main()
{
Uri prefix = new Uri("http://localhost/");
//A UriTemplate is a "URI with holes". It describes a set of URI's that
//are structurally similar. This UriTemplate might be used for organizing
//weather reports:
UriTemplate template = new UriTemplate("weather/{state}/{city}");
//You can convert a UriTemplate into a Uri by filling
//the holes in the template with parameters.
//BindByPosition moves left-to-right across the template
Uri positionalUri = template.BindByPosition(prefix, "Washington", "Redmond");
Console.WriteLine("Calling BindByPosition...");
Console.WriteLine(positionalUri);
Console.WriteLine();
//BindByName takes a NameValueCollection of parameters.
//Each parameter gets substituted into the UriTemplate "hole"
//that has the same name as the parameter.
NameValueCollection parameters = new NameValueCollection();
parameters.Add("state", "Washington");
parameters.Add("city", "Redmond");
Uri namedUri = template.BindByName(prefix, parameters);
Console.WriteLine("Calling BindByName...");
Console.WriteLine(namedUri);
Console.WriteLine();
//The inverse operation of Bind is Match(), which extrudes a URI
//through the template to produce a set of name/value pairs.
Uri fullUri = new Uri("http://localhost/weather/Washington/Redmond");
UriTemplateMatch results = template.Match(prefix, fullUri);
Console.WriteLine(String.Format("Matching {0} to {1}", template.ToString(), fullUri.ToString()));
if (results != null)
{
foreach (string variableName in results.BoundVariables.Keys)
{
Console.WriteLine(String.Format(" {0}: {1}", variableName, results.BoundVariables[variableName]));
}
}
Console.WriteLine("Press any key to terminate");
Console.ReadLine();
}
示例8: BindImageCacheUriTemplate
public static Uri BindImageCacheUriTemplate(Uri oBaseAddress, String strServerType, String strServer, String strLayer, TileInfo oTile)
{
UriTemplate oTemplate = new UriTemplate(ImageCacheUriTemplate);
NameValueCollection oParameters = new NameValueCollection();
oParameters.Add("serverType", HttpUtility.UrlEncode(strServerType));
oParameters.Add("server", HttpUtility.UrlEncode(strServer));
oParameters.Add("layer", HttpUtility.UrlEncode(strLayer));
oParameters.Add("level", oTile.Level.ToString(CultureInfo.InvariantCulture));
oParameters.Add("col", oTile.Column.ToString(CultureInfo.InvariantCulture));
oParameters.Add("row", oTile.Row.ToString(CultureInfo.InvariantCulture));
return oTemplate.BindByName(oBaseAddress, oParameters);
}
示例9: TestReservedExpansionReservedCharacters
public void TestReservedExpansionReservedCharacters()
{
string template = "{+path}/here";
UriTemplate uriTemplate = new UriTemplate(template);
Uri uri = uriTemplate.BindByName(Variables);
Assert.AreEqual("/foo/bar/here", uri.OriginalString);
UriTemplateMatch match = uriTemplate.Match(uri);
Assert.IsNotNull(match);
Assert.AreEqual(Variables["path"], match.Bindings["path"].Value);
match = uriTemplate.Match(uri, RequiredVariables);
Assert.IsNotNull(match);
Assert.AreEqual(Variables["path"], match.Bindings["path"].Value);
}
示例10: TestReservedExpansionEscaping
public void TestReservedExpansionEscaping()
{
string template = "{+hello}";
UriTemplate uriTemplate = new UriTemplate(template);
Uri uri = uriTemplate.BindByName(Variables);
Assert.AreEqual("Hello%20World!", uri.OriginalString);
UriTemplateMatch match = uriTemplate.Match(uri);
Assert.IsNotNull(match);
Assert.AreEqual(Variables["hello"], match.Bindings["hello"].Value);
match = uriTemplate.Match(uri, RequiredVariables);
Assert.IsNotNull(match);
Assert.AreEqual(Variables["hello"], match.Bindings["hello"].Value);
}
示例11: TestReservedExpansion
public void TestReservedExpansion()
{
string template = "{+var}";
UriTemplate uriTemplate = new UriTemplate(template);
Uri uri = uriTemplate.BindByName(Variables);
Assert.AreEqual("value", uri.OriginalString);
UriTemplateMatch match = uriTemplate.Match(uri);
Assert.IsNotNull(match);
Assert.AreEqual(Variables["var"], match.Bindings["var"].Value);
match = uriTemplate.Match(uri, RequiredVariables);
Assert.IsNotNull(match);
Assert.AreEqual(Variables["var"], match.Bindings["var"].Value);
}
示例12: TestSimpleExpansionEscaping
public void TestSimpleExpansionEscaping()
{
string template = "{hello}";
UriTemplate uriTemplate = new UriTemplate(template);
Uri uri = uriTemplate.BindByName(variables);
Assert.AreEqual("Hello%20World%21", uri.ToString());
UriTemplateMatch match = uriTemplate.Match(uri);
Assert.IsNotNull(match);
Assert.AreEqual(variables["hello"], match.Bindings["hello"].Value);
match = uriTemplate.Match(uri, requiredVariables);
Assert.IsNotNull(match);
Assert.AreEqual(variables["hello"], match.Bindings["hello"].Value);
}
示例13: TestCompoundFragmentExpansionCollectionVariable
public void TestCompoundFragmentExpansionCollectionVariable()
{
string template = "{#list*}";
UriTemplate uriTemplate = new UriTemplate(template);
Uri uri = uriTemplate.BindByName(variables);
Assert.AreEqual("#red,green,blue", uri.ToString());
UriTemplateMatch match = uriTemplate.Match(uri, new[] { "list" }, new[] { "keys" });
Assert.IsNotNull(match);
CollectionAssert.AreEqual((ICollection)variables["list"], (ICollection)match.Bindings["list"].Value);
match = uriTemplate.Match(uri, requiredVariables, new[] { "list" }, new[] { "keys" });
Assert.IsNotNull(match);
CollectionAssert.AreEqual((ICollection)variables["list"], (ICollection)match.Bindings["list"].Value);
}
示例14: TestSimpleExpansion
public void TestSimpleExpansion()
{
string template = "{var}";
UriTemplate uriTemplate = new UriTemplate(template);
Uri uri = uriTemplate.BindByName(variables);
Assert.AreEqual("value", uri.ToString());
UriTemplateMatch match = uriTemplate.Match(uri);
Assert.IsNotNull(match);
Assert.AreEqual(variables["var"], match.Bindings["var"].Value);
match = uriTemplate.Match(uri, requiredVariables);
Assert.IsNotNull(match);
Assert.AreEqual(variables["var"], match.Bindings["var"].Value);
}
示例15: TestFragmentExpansionMultipleVariablesAndLiteral
public void TestFragmentExpansionMultipleVariablesAndLiteral()
{
string template = "{#path,x}/here";
UriTemplate uriTemplate = new UriTemplate(template);
Uri uri = uriTemplate.BindByName(variables);
Assert.AreEqual("#/foo/bar,1024/here", uri.ToString());
UriTemplateMatch match = uriTemplate.Match(uri);
Assert.IsNotNull(match);
Assert.AreEqual(variables["path"], match.Bindings["path"].Value);
Assert.AreEqual(variables["x"], match.Bindings["x"].Value);
match = uriTemplate.Match(uri, requiredVariables);
Assert.IsNotNull(match);
Assert.AreEqual(variables["path"], match.Bindings["path"].Value);
Assert.AreEqual(variables["x"], match.Bindings["x"].Value);
}