首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何覆盖Awesomium ResourceInterceptor

如何覆盖Awesomium ResourceInterceptor
EN

Stack Overflow用户
提问于 2014-08-16 20:40:13
回答 1查看 1.2K关注 0票数 0

我想阻止Awesomium中的某些图片出现在页面上。此代码不能工作,因为Awesomium IResourceInterceptor不是一个类,它是一个接口。

代码语言:javascript
复制
public class ResourceInterceptor : IResourceInterceptor
{
public bool NoImages { get; set; }

private static string[] _imagesFileTypes = { ".png", ".jpg", ".jpeg", ".gif", ".bmp" };

public ResourceResponse OnRequest(ResourceRequest request)
{
    string ext = System.IO.Path.GetExtension(request.Url.ToString()).ToLower();

    if (NoImages && _imagesFileTypes.Contains(ext))
    {
        request.Cancel();
    }

    return null;
}

public bool OnFilterNavigation(NavigationRequest request)
{
    return false;
}

}

当一个IResourceInterceptor是一个接口时,如何修改它的IResourceInterceptor方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-22 09:44:27

您可以编写自己的接口实现。接口描述实现接口的类上可用的方法。因此,您可以编写实现IResourceInterceptor接口的自己的类,并像这样使用它:

在构造函数中,与往常一样:

代码语言:javascript
复制
WebCore.Initialized += WebCoreInitialzed; 
//create an instance of your Interceptor (you need a private field of course)
interceptor = new ResourceInterceptor();

在这种情况下,手持器功能:

代码语言:javascript
复制
private void WebCoreInitialzed(object sender, CoreStartEventArgs e)
{
    WebCore.ResourceInterceptor = interceptor;
}

如果您不熟悉接口的概念,您可能需要阅读msdn文章这里

这里可以找到一个可以列出某些教程的接口堆栈溢出问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25343775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档