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