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


C# Resolver.Add方法代码示例

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


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

示例1: TestCache

 public void TestCache() {
    Resolver<ContentType> resolver = new Resolver<ContentType>();
    resolver.Add(new ContentType("*.html", "text/html"));
    resolver.Add(new ContentType("*.jpg", "image/jpeg"));
    resolver.Add(new ContentType("/images/*", "image/jpeg"));
    resolver.Add(new ContentType("/log/**", "text/plain"));
    resolver.Add(new ContentType("*.exe", "application/octetstream"));
    resolver.Add(new ContentType("**.txt", "text/plain"));
    resolver.Add(new ContentType("/html/*", "text/html"));
    AssertEquals(7, resolver.Count);
    AssertEquals("image/jpeg", resolver.Resolve("image.jpg").Value);
    AssertEquals("text/plain", resolver.Resolve("README.txt").Value);
    int index = 0;
    for(int i = resolver.Count; i > 0; i--) {
       ContentType type = resolver[i - 1]; 
       if(type.Value.Equals("text/plain")) {
          index = i;
       }
    }
    resolver.RemoveAt(index);
    resolver.Add(new ContentType("*", "application/octetstream"));
    AssertEquals("application/octetstream", resolver.Resolve("README.txt").Value);
    AssertEquals("application/octetstream", resolver.Resolve("README.txt").Value);
    resolver.Add(new ContentType("README.*", "text/html"));
    resolver.Add(new ContentType("README.txt", "text/plain"));
    AssertEquals("text/plain", resolver.Resolve("README.txt").Value);
    AssertEquals("text/html", resolver.Resolve("README.jsp").Value);
 }
开发者ID:ngallagher,项目名称:simplexml,代码行数:28,代码来源:ResolverTest.cs

示例2: TestNoResolution

 public void TestNoResolution() {
    Resolver<ContentType> resolver = new Resolver<ContentType>();
    resolver.Add(new ContentType("*.html", "text/html"));
    resolver.Add(new ContentType("*.jpg", "image/jpeg"));
    resolver.Add(new ContentType("/images/*", "image/jpeg"));
    resolver.Add(new ContentType("/log/**", "text/plain"));
    resolver.Add(new ContentType("*.exe", "application/octetstream"));
    resolver.Add(new ContentType("**.txt", "text/plain"));
    resolver.Add(new ContentType("/html/*", "text/html"));
    AssertEquals(7, resolver.Count);
    AssertEquals("text/plain", resolver.Resolve("README.txt").Value);
    AssertEquals(null, resolver.Resolve("README"));
 }
开发者ID:ngallagher,项目名称:simplexml,代码行数:13,代码来源:ResolverTest.cs

示例3: TestNonGreedyMatch

 public void TestNonGreedyMatch() {
    Resolver<ContentType> resolver = new Resolver<ContentType>();
    resolver.Add(new ContentType("*.html", "text/html"));
    resolver.Add(new ContentType("*.jpg", "image/jpeg"));
    resolver.Add(new ContentType("/images/*", "image/jpeg"));
    resolver.Add(new ContentType("/log/**", "text/plain"));
    resolver.Add(new ContentType("*.exe", "application/octetstream"));
    resolver.Add(new ContentType("**.txt", "text/plain"));
    resolver.Add(new ContentType("/html/*", "text/html"));
    AssertEquals(7, resolver.Count);
    resolver.Add(new ContentType("/*?/html/*", "text/html"));
    AssertEquals(8, resolver.Count);
    AssertEquals(null, resolver.Resolve("/a/b/html/index.jsp"));
    AssertEquals("text/html", resolver.Resolve("/a/html/index.jsp").Value);
 }
开发者ID:ngallagher,项目名称:simplexml,代码行数:15,代码来源:ResolverTest.cs

示例4: TestResolverCache

 public void TestResolverCache() {
    Resolver<ContentType> resolver = new Resolver<ContentType>();
    for(int i = 0; i <= 2000; i++) {
       resolver.Add(new ContentType(i.ToString(), i.ToString()));
    }
    AssertEquals(resolver.Resolve("1").Value, "1");
    AssertEquals(resolver.Resolve("2000").Value, "2000");
 }
开发者ID:ngallagher,项目名称:simplexml,代码行数:8,代码来源:ResolverTest.cs


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