当前位置: 首页>>代码示例>>C#>>正文


C# UriTemplate.GetParameterNames方法代码示例

本文整理汇总了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;
        }
开发者ID:IsaacSanch,项目名称:APIology.HAL,代码行数:50,代码来源:HalLink.cs

示例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);
        }
开发者ID:restfulobjects,项目名称:restfulobjects-wsa,代码行数:43,代码来源:RORequest.cs

示例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;
        }
开发者ID:Herbert42,项目名称:gedcomx-csharp,代码行数:32,代码来源:Link.cs

示例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();
 }
开发者ID:Herbert42,项目名称:gedcomx-csharp,代码行数:9,代码来源:Link.cs


注:本文中的Tavis.UriTemplates.UriTemplate.GetParameterNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。