本文整理匯總了C#中System.UriTemplate.AddPathVariable方法的典型用法代碼示例。如果您正苦於以下問題:C# UriTemplate.AddPathVariable方法的具體用法?C# UriTemplate.AddPathVariable怎麽用?C# UriTemplate.AddPathVariable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.UriTemplate
的用法示例。
在下文中一共展示了UriTemplate.AddPathVariable方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateFromUriTemplate
public static UriTemplatePathSegment CreateFromUriTemplate(string segment, UriTemplate template)
{
// Identifying the type of segment - Literal|Compound|Variable
switch (UriTemplateHelpers.IdentifyPartType(segment))
{
case UriTemplatePartType.Literal:
return UriTemplateLiteralPathSegment.CreateFromUriTemplate(segment, template);
case UriTemplatePartType.Compound:
return UriTemplateCompoundPathSegment.CreateFromUriTemplate(segment, template);
case UriTemplatePartType.Variable:
if (segment.EndsWith("/", StringComparison.Ordinal))
{
string varName = template.AddPathVariable(UriTemplatePartType.Variable,
segment.Substring(1, segment.Length - 3));
return new UriTemplateVariablePathSegment(segment, true, varName);
}
else
{
string varName = template.AddPathVariable(UriTemplatePartType.Variable,
segment.Substring(1, segment.Length - 2));
return new UriTemplateVariablePathSegment(segment, false, varName);
}
default:
Fx.Assert("Invalid value from IdentifyStringNature");
return null;
}
}
示例2: CreateFromUriTemplate
public static UriTemplatePathSegment CreateFromUriTemplate(string segment, UriTemplate template)
{
switch (UriTemplateHelpers.IdentifyPartType(segment))
{
case UriTemplatePartType.Literal:
return UriTemplateLiteralPathSegment.CreateFromUriTemplate(segment, template);
case UriTemplatePartType.Compound:
return UriTemplateCompoundPathSegment.CreateFromUriTemplate(segment, template);
case UriTemplatePartType.Variable:
if (!segment.EndsWith("/", StringComparison.Ordinal))
{
return new UriTemplateVariablePathSegment(segment, false, template.AddPathVariable(UriTemplatePartType.Variable, segment.Substring(1, segment.Length - 2)));
}
return new UriTemplateVariablePathSegment(segment, true, template.AddPathVariable(UriTemplatePartType.Variable, segment.Substring(1, segment.Length - 3)));
}
return null;
}