本文整理汇总了C#中Tavis.UriTemplates.UriTemplate类的典型用法代码示例。如果您正苦于以下问题:C# UriTemplate类的具体用法?C# UriTemplate怎么用?C# UriTemplate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UriTemplate类属于Tavis.UriTemplates命名空间,在下文中一共展示了UriTemplate类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_generate_a_fully_qualified_path
public void Can_generate_a_fully_qualified_path()
{
string expected = _baseUrl + "foo/1";
const string routeName = "foo.show";
const string routeTemplate = "foo/{id}";
string template = TestHelper.CreateATemplateGenerator(_baseUrl, routeName, routeTemplate)
.Generate(routeName);
var uriTemplate = new UriTemplate(template);
uriTemplate.AddParameter("id", 1);
string actual = uriTemplate.Resolve();
Assert.Equal(expected, actual);
}
示例2: Can_generate_two_optional_path_items_template
public void Can_generate_two_optional_path_items_template()
{
string expected = _baseUrl + "foo/2";
const string routeName = "foo.one.two";
const string routeTemplate = "foo/{one}/{two}";
string template = TestHelper.CreateATemplateGenerator(_baseUrl, routeName, routeTemplate,
routeDefaults: new { one = RouteParameter.Optional, two = RouteParameter.Optional })
.Generate(routeName, new { two = 2 });
var uriTemplate = new UriTemplate(template);
uriTemplate.AddParameter("two", "2");
string actual = uriTemplate.Resolve();
Assert.Equal(expected, actual);
}
示例3: Can_generate_a_path_with_anonymous_complex_route_properties
public void Can_generate_a_path_with_anonymous_complex_route_properties()
{
string expected = _baseUrl + "foo/1?bar.abc=abc&bar.def=def";
const string routeName = "foo.show";
const string routeTemplate = "foo/{id}";
string template = TestHelper.CreateATemplateGenerator(_baseUrl, routeName, routeTemplate)
.Generate(routeName, new { Id = 1, Bar = new { Abc = "abc", Def = "def" } });
var uriTemplate = new UriTemplate(template);
uriTemplate.AddParameters(new { id = 1 });
uriTemplate.AddParameter("bar.abc", "abc");
uriTemplate.AddParameter("bar.def", "def");
string actual = uriTemplate.Resolve();
Assert.Equal(expected, actual);
}
示例4: BuildInstance
public ResourceOptions BuildInstance()
{
var metadata = _metadataProvider.BuildInstance();
var resources = metadata.Resources;
var supportedParameters = new Dictionary<string, object>{ {"hash", metadata.Hash} };
var browserAgentScriptTemplate = new UriTemplate(resources.GetValueOrDefault("agent", string.Empty), true);
var httpMessageTemplate = new UriTemplate(resources.GetValueOrDefault("message-ingress", string.Empty), true);
var hudScriptTemplate = new UriTemplate(resources.GetValueOrDefault("hud", string.Empty), true);
var contextTemplate = new UriTemplate(resources.GetValueOrDefault("context", string.Empty), true);
var metadataTemplate = new UriTemplate(resources.GetValueOrDefault("metadata", string.Empty), true);
var clientScriptTemplate = new UriTemplate(resources.GetValueOrDefault("client", string.Empty), true);
return new ResourceOptions
{
BrowserAgentScriptTemplate = browserAgentScriptTemplate.ResolveWith(supportedParameters),
MessageIngressTemplate = httpMessageTemplate.ResolveWith(supportedParameters),
HudScriptTemplate = hudScriptTemplate.ResolveWith(supportedParameters),
ContextTemplate = contextTemplate.ResolveWith(supportedParameters),
MetadataTemplate = metadataTemplate.ResolveWith(supportedParameters),
ClientScriptTemplate = clientScriptTemplate.ResolveWith(supportedParameters)
};
}