本文整理汇总了C#中System.Uri.MakeTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.MakeTemplate方法的具体用法?C# Uri.MakeTemplate怎么用?C# Uri.MakeTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Uri
的用法示例。
在下文中一共展示了Uri.MakeTemplate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Remove_an_existing_parameter
public void Remove_an_existing_parameter()
{
var target = new Uri("http://example/customer?view=False&foo=bar");
var template = target.MakeTemplate();
template.ClearParameter("view");
Assert.Equal("http://example/customer?foo=bar", template.Resolve());
}
示例2: Change_an_existing_parameter
public void Change_an_existing_parameter()
{
var target = new Uri("http://example/customer?view=False&foo=bar");
var template = target.MakeTemplate();
template.SetParameter("view",true);
Assert.Equal("http://example/customer?view=True&foo=bar", template.Resolve());
}
示例3: Remove_a_query_parameters2
public void Remove_a_query_parameters2()
{
var target = new Uri("http://example.org/customer?format=xml&id=23");
var template = target.MakeTemplate();
template.ClearParameter("format");
Assert.Equal("http://example.org/customer?id=23", template.Resolve());
}
示例4: Change_an_existing_parameter_within_multiple
public void Change_an_existing_parameter_within_multiple()
{
var target = new Uri("http://example/customer?view=False&foo=bar");
var parameters = target.GetQueryStringParameters();
parameters["view"] = true;
var template = target.MakeTemplate(parameters);
Assert.Equal("http://example/customer?view=True&foo=bar", template.Resolve());
}
示例5: Add_parameters_to_uri_with_query_string_ignoring_path_parameter
public void Add_parameters_to_uri_with_query_string_ignoring_path_parameter()
{
var target = new Uri("http://example/customer/{id}?view=true");
var template = target.MakeTemplate(target.GetQueryStringParameters()
.Union(new Dictionary<string, object> {{"context", "detail"}})
.ToDictionary(k=> k.Key, v=> v.Value));
template.AddParameter("id", 99);
Assert.Equal("http://example/customer/99?view=true&context=detail", template.Resolve());
}
示例6: Add_multiple_parameters_to_uri
public void Add_multiple_parameters_to_uri()
{
var target = new Uri("http://example/customer");
var template = target.MakeTemplate(new Dictionary<string, object>
{
{"id", 99},
{"view", false}
});
Assert.Equal("http://example/customer?id=99&view=False", template.Resolve());
}
示例7: Foo
public void Foo()
{
var foo = new Foo()
{
Bar = "hello world",
Baz = 10
};
var uri = new Uri("http://example.org/blah");
var uri2 = uri.MakeTemplate(Tavis.UriExtensions.ObjectToDictionary(foo));
Assert.Equal("http://example.org/blah?Bar=hello%20world&Baz=10", uri2.Resolve());
}