我有这个简单的代码:
class ResourceInterceptor: IResourceInterceptor
{
public bool OnFilterNavigation(NavigationRequest request)
{
return false;
}
ResourceResponse IResourceInterceptor.OnRequest(ResourceRequest request)
{
request.Referrer = "http://www.google.com";
return null;
}
}
我需要将一个变量传递给类(只需阅读它,不要编辑),但如果我插入一个未在类中声明的变量,它会给我这个错误:
无法通过嵌套类型“WindowsFormsApplication1.Form1.ResourceInterceptor”访问外部类型“WindowsFormsApplication1.Form1”的非静态成员
例如我需要这样的东西(显然不起作用!)
public string referrer = "www.google.com";
class ResourceInterceptor: IResourceInterceptor
{
public bool OnFilterNavigation(NavigationRequest request)
{
return false;
}
ResourceResponse IResourceInterceptor.OnRequest(ResourceRequest request)
{
request.Referrer = referrer;
return null;
}
}