當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。