本文整理汇总了C#中Tavis.UriTemplates.UriTemplate.GetParameterNames方法的典型用法代码示例。如果您正苦于以下问题:C# UriTemplate.GetParameterNames方法的具体用法?C# UriTemplate.GetParameterNames怎么用?C# UriTemplate.GetParameterNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tavis.UriTemplates.UriTemplate
的用法示例。
在下文中一共展示了UriTemplate.GetParameterNames方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveFor
public HalLink ResolveFor(object Dto, IHalModelConfig config, JsonSerializer serializer, object memberValue = null)
{
var clone = MemberwiseClone() as HalLink;
var dtoType = Dto?.GetType();
UriTemplate template;
if (string.IsNullOrEmpty(Href))
{
template = new UriTemplate(memberValue as string, true, false);
}
else
{
template = new UriTemplate(Href, true, false);
foreach (string param in template.GetParameterNames())
{
object value;
if (param == "value")
value = memberValue;
else
value = dtoType?.GetProperty(param)?.GetValue(Dto);
if (value != null)
{
if (value is string == false)
{
var token = JToken.FromObject(value, serializer);
value = token.Type == JTokenType.String ?
token.Value<string>() : value;
}
template.SetParameter(param, value);
}
}
}
var linkUri = new Uri(template.Resolve(), UriKind.RelativeOrAbsolute);
if (!linkUri.IsAbsoluteUri)
{
var baseUri = new Uri(config.RequestPathBase);
string basePath = baseUri.GetLeftPart(UriPartial.Authority) +
VirtualPathUtility.ToAbsolute(config.RelativePathBase, baseUri.AbsolutePath);
linkUri = new Uri(new Uri(basePath), linkUri);
}
clone.Href = linkUri.ToString();
return clone;
}
示例2: AsUriStr
public string AsUriStr()
{
if (_path != null)
{
return _path;
}
if (_resource._uriTemplateStr != null)
{
var template = new UriTemplate(_resource._uriTemplateStr);
var parameterNames = template.GetParameterNames();
var parameterNameList = parameterNames as IList<string> ?? parameterNames.ToList();
if (_pathElements != null)
{
if (parameterNameList.Count() != _pathElements.Count())
{
throw new ArgumentException(String.Format("Mismatch between parameters in uriTemplate and supplied elements; uriTemplate={0}, elements={1}", template.Template, _pathElements));
}
int i = 0;
foreach (var parameterName in parameterNameList)
{
template.SetParameter(parameterName, _pathElements[i++]);
}
}
else
{
var pathElementMapKeys = _pathElementMap.Keys;
var argsWithNoParams = pathElementMapKeys.Except(parameterNameList);
var paramsWithNoArgs = parameterNameList.Except(pathElementMapKeys);
if (argsWithNoParams.Any() || paramsWithNoArgs.Any())
{
throw new ArgumentException(String.Format("Mismatch between parameters in uriTemplate and supplied map; uriTemlpate={0}, map={1}", template.Template, _pathElementMap));
}
foreach (var parameterName in parameterNameList)
{
template.SetParameter(parameterName, _pathElementMap[parameterName]);
}
}
return PrefixBaseIfRequired(template.Resolve());
}
// else
return PrefixBaseIfRequired(_resource._uriStr);
}
示例3: GetResolvedTarget
/// <summary>
/// Resolves the URI Template defined in the Target URI using the assigned URI parameters
/// </summary>
/// <returns></returns>
public Uri GetResolvedTarget()
{
if (Target != null )
{
var uriTemplate = new UriTemplate(Target.OriginalString);
if (AddNonTemplatedParametersToQueryString)
{
var templateParameters = uriTemplate.GetParameterNames();
if (_Parameters.Any(p => !templateParameters.Contains(p.Key)))
{
AddParametersAsTemplate();
uriTemplate = new UriTemplate(Target.OriginalString);
}
}
if (Target.OriginalString.Contains("{"))
{
ApplyParameters(uriTemplate);
var resolvedTarget = new Uri(uriTemplate.Resolve(), UriKind.RelativeOrAbsolute);
return resolvedTarget;
}
}
return Target;
}
示例4: GetParameterNames
/// <summary>
/// Returns list of URI Template parameters specified in the Target URI
/// </summary>
/// <returns></returns>
public IEnumerable<string> GetParameterNames()
{
var uriTemplate = new UriTemplate(Target.OriginalString);
return uriTemplate.GetParameterNames();
}