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


C# UriTemplate.BindByName方法代码示例

本文整理汇总了C#中System.UriTemplate.BindByName方法的典型用法代码示例。如果您正苦于以下问题:C# UriTemplate.BindByName方法的具体用法?C# UriTemplate.BindByName怎么用?C# UriTemplate.BindByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.UriTemplate的用法示例。


在下文中一共展示了UriTemplate.BindByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildUriString

 public string BuildUriString(NancyContext context, string routeName, dynamic parameters)
 {
     var baseUri = new Uri(context.Request.BaseUri().TrimEnd('/'));
       var pathTemplate = AllRoutes.Single(r => r.Name == routeName).Path;
       var uriTemplate = new UriTemplate(pathTemplate, true);
       return uriTemplate.BindByName(baseUri, ToDictionary(parameters ?? new {})).ToString();
 }
开发者ID:horsdal,项目名称:Restbucks-on-Nancy,代码行数:7,代码来源:ResourceLinker.cs

示例2: TestCompoundFragmentExpansionAssociativeMapVariable

        public void TestCompoundFragmentExpansionAssociativeMapVariable()
        {
            string template = "{#keys*}";
            UriTemplate uriTemplate = new UriTemplate(template);
            Uri uri = uriTemplate.BindByName(variables);
            string[] allowed =
                {
                    "#comma=,,dot=.,semi=;",
                    "#comma=,,semi=;,dot=.",
                    "#dot=.,comma=,,semi=;",
                    "#dot=.,semi=;,comma=,",
                    "#semi=;,comma=,,dot=.",
                    "#semi=;,dot=.,comma=,"
                };

            CollectionAssert.Contains(allowed, uri.ToString());

            UriTemplateMatch match = uriTemplate.Match(uri, new[] { "list" }, new[] { "keys" });
            Assert.IsNotNull(match);
            CollectionAssert.AreEqual((ICollection)variables["keys"], (ICollection)match.Bindings["keys"].Value);

            match = uriTemplate.Match(uri, requiredVariables, new[] { "list" }, new[] { "keys" });
            Assert.IsNotNull(match);
            CollectionAssert.AreEqual((ICollection)variables["keys"], (ICollection)match.Bindings["keys"].Value);
        }
开发者ID:gitter-badger,项目名称:dotnet-uritemplate,代码行数:25,代码来源:Level4Tests.cs

示例3: BuildUriString

        public string BuildUriString(string prefix, string template, dynamic parameters)
        {
            var newBaseUri = new Uri(baseUri.TrimEnd('/') + prefix);
              var uriTemplate = new UriTemplate(template, true);

              return uriTemplate.BindByName(newBaseUri, ToDictionary(parameters ?? new {})).ToString();
        }
开发者ID:saberone,项目名称:RestBench,代码行数:7,代码来源:ResourceLinker.cs

示例4: TestEmptyTemplate

        public void TestEmptyTemplate()
        {
            string template = string.Empty;
            UriTemplate uriTemplate = new UriTemplate(template);
            Uri uri = uriTemplate.BindByName(variables);
            Assert.AreEqual(string.Empty, uri.ToString());

            UriTemplateMatch match = uriTemplate.Match(uri);
            Assert.IsNotNull(match);
            Assert.AreEqual(0, match.Bindings.Count);
        }
开发者ID:gitter-badger,项目名称:dotnet-uritemplate,代码行数:11,代码来源:Level1Tests.cs

示例5: BindTemplate

 private static Uri BindTemplate(Uri baseUri, UriTemplate template, object parameters = null)
 {
     if (parameters == null)
       {
     Dictionary<string, string> emptyParameters = new Dictionary<string, string>();
     return template.BindByName(baseUri, emptyParameters);
       }
       else if (parameters is IDictionary<string, string>)
       {
     return template.BindByName(baseUri, (IDictionary<string, string>)parameters);
       }
       else if (parameters is NameValueCollection)
       {
     return template.BindByName(baseUri, (NameValueCollection)parameters);
       }
       else
       {
     Dictionary<string, string> parameterDictionary = DictionaryConverter.ConvertObjectPropertiesToDictionary(parameters);
     return template.BindByName(baseUri, parameterDictionary);
       }
 }
开发者ID:prearrangedchaos,项目名称:Ramone,代码行数:21,代码来源:BindingExtensions.cs

示例6: Experiment

 public void Experiment()
 {
     var template = new UriTemplate("devices/{deviceId}/messages/outbound/{*subTopic}");
     var baseUri = new Uri("http://whatever");
     Uri bound = template.BindByName(baseUri, new Dictionary<string, string>
     {
         { "deviceId", "VINno" },
         { "SubTopic", "toptop/toptoptop" },
     });
     var t2 = new UriTemplate("devices/{deviceId}/messages/log/{level=info}/{subject=n%2Fa}", true);
     UriTemplateMatch match = t2.Match(baseUri, new Uri("http://whatever/devices/VINno/messages/log", UriKind.Absolute));
 }
开发者ID:kdotchkoff,项目名称:azure-iot-protocol-gateway,代码行数:12,代码来源:MqttTopicMatchingTests.cs

示例7: Main

        public static void Main()
        {
            Uri prefix = new Uri("http://localhost/");

            //A UriTemplate is a "URI with holes". It describes a set of URI's that
            //are structurally similar. This UriTemplate might be used for organizing
            //weather reports:
            UriTemplate template = new UriTemplate("weather/{state}/{city}");

            //You can convert a UriTemplate into a Uri by filling
            //the holes in the template with parameters.

            //BindByPosition moves left-to-right across the template
            Uri positionalUri = template.BindByPosition(prefix, "Washington", "Redmond");

            Console.WriteLine("Calling BindByPosition...");
            Console.WriteLine(positionalUri);
            Console.WriteLine();

            //BindByName takes a NameValueCollection of parameters. 
            //Each parameter gets substituted into the UriTemplate "hole"
            //that has the same name as the parameter.
            NameValueCollection parameters = new NameValueCollection();
            parameters.Add("state", "Washington");
            parameters.Add("city", "Redmond");

            Uri namedUri = template.BindByName(prefix, parameters);

            Console.WriteLine("Calling BindByName...");
            Console.WriteLine(namedUri);
            Console.WriteLine();


            //The inverse operation of Bind is Match(), which extrudes a URI
            //through the template to produce a set of name/value pairs.
            Uri fullUri = new Uri("http://localhost/weather/Washington/Redmond");
            UriTemplateMatch results = template.Match(prefix, fullUri);

            Console.WriteLine(String.Format("Matching {0} to {1}", template.ToString(), fullUri.ToString()));

            if (results != null)
            {
                foreach (string variableName in results.BoundVariables.Keys)
                {
                    Console.WriteLine(String.Format("   {0}: {1}", variableName, results.BoundVariables[variableName]));
                }
            }

            Console.WriteLine("Press any key to terminate");
            Console.ReadLine();
        }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:51,代码来源:Program.cs

示例8: BindImageCacheUriTemplate

        public static Uri BindImageCacheUriTemplate(Uri oBaseAddress, String strServerType, String strServer, String strLayer, TileInfo oTile)
        {
            UriTemplate oTemplate = new UriTemplate(ImageCacheUriTemplate);

            NameValueCollection oParameters = new NameValueCollection();
            oParameters.Add("serverType", HttpUtility.UrlEncode(strServerType));
            oParameters.Add("server", HttpUtility.UrlEncode(strServer));
            oParameters.Add("layer", HttpUtility.UrlEncode(strLayer));
            oParameters.Add("level", oTile.Level.ToString(CultureInfo.InvariantCulture));
            oParameters.Add("col", oTile.Column.ToString(CultureInfo.InvariantCulture));
            oParameters.Add("row", oTile.Row.ToString(CultureInfo.InvariantCulture));

            return oTemplate.BindByName(oBaseAddress, oParameters);
        }
开发者ID:paladin74,项目名称:Dapple,代码行数:14,代码来源:Contract.cs

示例9: TestReservedExpansionReservedCharacters

        public void TestReservedExpansionReservedCharacters()
        {
            string template = "{+path}/here";
            UriTemplate uriTemplate = new UriTemplate(template);
            Uri uri = uriTemplate.BindByName(Variables);
            Assert.AreEqual("/foo/bar/here", uri.OriginalString);

            UriTemplateMatch match = uriTemplate.Match(uri);
            Assert.IsNotNull(match);
            Assert.AreEqual(Variables["path"], match.Bindings["path"].Value);

            match = uriTemplate.Match(uri, RequiredVariables);
            Assert.IsNotNull(match);
            Assert.AreEqual(Variables["path"], match.Bindings["path"].Value);
        }
开发者ID:manuc66,项目名称:dotnet-uritemplate,代码行数:15,代码来源:Level2Tests.cs

示例10: TestReservedExpansionEscaping

        public void TestReservedExpansionEscaping()
        {
            string template = "{+hello}";
            UriTemplate uriTemplate = new UriTemplate(template);
            Uri uri = uriTemplate.BindByName(Variables);
            Assert.AreEqual("Hello%20World!", uri.OriginalString);

            UriTemplateMatch match = uriTemplate.Match(uri);
            Assert.IsNotNull(match);
            Assert.AreEqual(Variables["hello"], match.Bindings["hello"].Value);

            match = uriTemplate.Match(uri, RequiredVariables);
            Assert.IsNotNull(match);
            Assert.AreEqual(Variables["hello"], match.Bindings["hello"].Value);
        }
开发者ID:manuc66,项目名称:dotnet-uritemplate,代码行数:15,代码来源:Level2Tests.cs

示例11: TestReservedExpansion

        public void TestReservedExpansion()
        {
            string template = "{+var}";
            UriTemplate uriTemplate = new UriTemplate(template);
            Uri uri = uriTemplate.BindByName(Variables);
            Assert.AreEqual("value", uri.OriginalString);

            UriTemplateMatch match = uriTemplate.Match(uri);
            Assert.IsNotNull(match);
            Assert.AreEqual(Variables["var"], match.Bindings["var"].Value);

            match = uriTemplate.Match(uri, RequiredVariables);
            Assert.IsNotNull(match);
            Assert.AreEqual(Variables["var"], match.Bindings["var"].Value);
        }
开发者ID:manuc66,项目名称:dotnet-uritemplate,代码行数:15,代码来源:Level2Tests.cs

示例12: TestSimpleExpansionEscaping

        public void TestSimpleExpansionEscaping()
        {
            string template = "{hello}";
            UriTemplate uriTemplate = new UriTemplate(template);
            Uri uri = uriTemplate.BindByName(variables);
            Assert.AreEqual("Hello%20World%21", uri.ToString());

            UriTemplateMatch match = uriTemplate.Match(uri);
            Assert.IsNotNull(match);
            Assert.AreEqual(variables["hello"], match.Bindings["hello"].Value);

            match = uriTemplate.Match(uri, requiredVariables);
            Assert.IsNotNull(match);
            Assert.AreEqual(variables["hello"], match.Bindings["hello"].Value);
        }
开发者ID:gitter-badger,项目名称:dotnet-uritemplate,代码行数:15,代码来源:Level1Tests.cs

示例13: TestCompoundFragmentExpansionCollectionVariable

        public void TestCompoundFragmentExpansionCollectionVariable()
        {
            string template = "{#list*}";
            UriTemplate uriTemplate = new UriTemplate(template);
            Uri uri = uriTemplate.BindByName(variables);
            Assert.AreEqual("#red,green,blue", uri.ToString());

            UriTemplateMatch match = uriTemplate.Match(uri, new[] { "list" }, new[] { "keys" });
            Assert.IsNotNull(match);
            CollectionAssert.AreEqual((ICollection)variables["list"], (ICollection)match.Bindings["list"].Value);

            match = uriTemplate.Match(uri, requiredVariables, new[] { "list" }, new[] { "keys" });
            Assert.IsNotNull(match);
            CollectionAssert.AreEqual((ICollection)variables["list"], (ICollection)match.Bindings["list"].Value);
        }
开发者ID:gitter-badger,项目名称:dotnet-uritemplate,代码行数:15,代码来源:Level4Tests.cs

示例14: TestSimpleExpansion

        public void TestSimpleExpansion()
        {
            string template = "{var}";
            UriTemplate uriTemplate = new UriTemplate(template);
            Uri uri = uriTemplate.BindByName(variables);
            Assert.AreEqual("value", uri.ToString());

            UriTemplateMatch match = uriTemplate.Match(uri);
            Assert.IsNotNull(match);
            Assert.AreEqual(variables["var"], match.Bindings["var"].Value);

            match = uriTemplate.Match(uri, requiredVariables);
            Assert.IsNotNull(match);
            Assert.AreEqual(variables["var"], match.Bindings["var"].Value);
        }
开发者ID:gitter-badger,项目名称:dotnet-uritemplate,代码行数:15,代码来源:Level1Tests.cs

示例15: TestFragmentExpansionMultipleVariablesAndLiteral

        public void TestFragmentExpansionMultipleVariablesAndLiteral()
        {
            string template = "{#path,x}/here";
            UriTemplate uriTemplate = new UriTemplate(template);
            Uri uri = uriTemplate.BindByName(variables);
            Assert.AreEqual("#/foo/bar,1024/here", uri.ToString());

            UriTemplateMatch match = uriTemplate.Match(uri);
            Assert.IsNotNull(match);
            Assert.AreEqual(variables["path"], match.Bindings["path"].Value);
            Assert.AreEqual(variables["x"], match.Bindings["x"].Value);

            match = uriTemplate.Match(uri, requiredVariables);
            Assert.IsNotNull(match);
            Assert.AreEqual(variables["path"], match.Bindings["path"].Value);
            Assert.AreEqual(variables["x"], match.Bindings["x"].Value);
        }
开发者ID:gitter-badger,项目名称:dotnet-uritemplate,代码行数:17,代码来源:Level3Tests.cs


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