本文整理汇总了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);
}
示例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"));
}
示例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);
}
示例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");
}