-3

I am trying to convert a piece of code from C# to VB.NET

public class ResourceInterceptor : IResourceInterceptor
{
    public bool NoImages { get; set; }

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

    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;
    }
}

I tried to do it like this:

Public Class ResourceInterceptor
    Implements IResourceInterceptor

    Public Property NoImages() As Boolean
        Get
            Return _bNoImages
        End Get
        Set(value As Boolean)
            _bNoImages = value
        End Set
    End Property

    Private _bNoImages As Boolean

    Private Shared _imagesFileTypes As String() = {".png", ".jpg", ".jpeg", ".gif", ".bmp", ".swf"}
    'private static string[] _imagesFileTypes = { ".gif", ".swf" };

    Public Function OnRequest(request As ResourceRequest) As Boolean Implements IResourceInterceptor.OnRequest

        Dim ext As String = System.IO.Path.GetExtension(request.Url.ToString()).ToLower()

        If _bNoImages AndAlso _imagesFileTypes.Contains(ext) Then
            request.Cancel()
        End If

        Return Nothing

    End Function

    Function OnFilterNavigation(ByRef request As NavigationRequest) As Boolean Implements IResourceInterceptor.OnFilterNavigation
        Return False
    End Function

End Class

But I made a mistake converting the Implements code, I think.

I guess that it is pretty obvious that I have no idea what I am doing here. Could somebody help, please?

The error I am getting is "Class 'ResourceInterceptor' needs to implement 'Function OnFilterNavigation(request As NavigationRequest) As Boolean for Awesomium.Core.IResourceInterceptor."

Mark
  • 8,140
  • 1
  • 14
  • 29
tmighty
  • 10,734
  • 21
  • 104
  • 218
  • 1
    Why not simply pay someone who does know? Otherwise please clarify what exact piece of code causes problem during conversion for you. – Alexei Levenkov Jun 11 '14 at 22:15
  • I did. I edited my post. – tmighty Jun 11 '14 at 22:15
  • 1
    Why compile it in C# and use something like dotPeek to decompile it into VB.NET? – Pete Garafano Jun 11 '14 at 22:16
  • 1
    Probably just remove the `ByRef` - `Function OnFilterNavigation(request As NavigationRequest) As Boolean Implements IResourceInterceptor.OnFilterNavigation`. – Mark Jun 11 '14 at 22:17
  • 1
    Your function gets the request parameter `ByRef` while it should be `ByVal` (or just omit it). It isn't byref either in the C# code... Also, the error message kinda indicates this too. – Styxxy Jun 11 '14 at 22:17
  • @Styxxy Thank you very much! That helped! Can you make your comment the reply? – tmighty Jun 11 '14 at 22:18

1 Answers1

1

The request parameter should not be passed ByRef, it should be passed ByVal, which is the default if you don't specify anything. i.e.

Function OnFilterNavigation(request As NavigationRequest) As Boolean Implements IResourceInterceptor.OnFilterNavigation
Mark
  • 8,140
  • 1
  • 14
  • 29