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


C# UriTemplate.Match方法代码示例

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


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

示例1: 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

示例2: 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

示例3: TestReservedExpansionReservedCharacters

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

            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:gitter-badger,项目名称:dotnet-uritemplate,代码行数:15,代码来源:Level2Tests.cs

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: TryUriTemplateMatch

 private bool TryUriTemplateMatch(string uri, out UriTemplateMatch uriTemplateMatch)
 {
     var uriTemplate = new UriTemplate(uri);
     var serverPath = Request.Url.GetServerBaseUri();
     uriTemplateMatch = uriTemplate.Match(new Uri(serverPath), Request.Url);
     return uriTemplateMatch != null;
 }
开发者ID:JamesTryand,项目名称:minimods,代码行数:7,代码来源:HttpContext.cs

示例9: when_validating_a_uri_template_with_url_encoded_chars

 public void when_validating_a_uri_template_with_url_encoded_chars()
 {
     var template = new UriTemplate("/streams/$all?embed={embed}");
     var uri = new Uri("http://127.0.0.1/streams/$all");
     var baseaddress = new Uri("http://127.0.0.1");
     Assert.IsTrue(template.Match(baseaddress, uri) != null);
 }        
开发者ID:thinkbeforecoding,项目名称:EventStore,代码行数:7,代码来源:mono_filestream_bug.cs

示例10: 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

示例11: TestFragmentExpansionMultipleVariables

        public void TestFragmentExpansionMultipleVariables()
        {
            string template = "{#x,hello,y}";
            UriTemplate uriTemplate = new UriTemplate(template);
            Uri uri = uriTemplate.BindByName(variables);
            Assert.AreEqual("#1024,Hello%20World!,768", uri.ToString());

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

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

示例12: 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

示例13: 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

示例14: Matches

        public bool Matches(RequestContext ctx)
        {
            if (!String.IsNullOrEmpty(method) && ctx.Request.HttpMethod != method) return false;

            var uriTemplate = new UriTemplate(uri);
            var serverPath = ctx.Request.Url.GetServerBaseUri();
            var uriTemplateMatch = uriTemplate.Match(new Uri(serverPath), ctx.Request.Url);
            if (uriTemplateMatch == null) return false;

            ctx.Request.LoadArguments(uriTemplateMatch.BoundVariables);
            return true;
        }
开发者ID:NickLydon,项目名称:Anna,代码行数:12,代码来源:UrlTemplateMatcher.cs

示例15: 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


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