How would you convert this to valid VB.NET?

I found an article on removing whitespace from my markup in ASP.NET MVC, however, when I use the code converter, the "function" is not properly converted

public class WhitespaceFilterAttribute : ActionFilterAttribute
    {

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {

            var request = filterContext.HttpContext.Request;
            var response = filterContext.HttpContext.Response;

            response.Filter = new WhiteSpaceFilter(response.Filter, s =>
                    {
                        s = Regex.Replace(s, @"\s+", " ");
                        s = Regex.Replace(s, @"\s*\n\s*", "\n");
                        s = Regex.Replace(s, @"\s*\>\s*\<\s*", "><");
                        s = Regex.Replace(s, @"<!--(.*?)-->", "");   //Remove comments

                        // single-line doctype must be preserved 
                        var firstEndBracketPosition = s.IndexOf(">");
                        if (firstEndBracketPosition >= 0)
                        {
                            s = s.Remove(firstEndBracketPosition, 1);
                            s = s.Insert(firstEndBracketPosition, ">");
                        }
                        return s;
                    });

            }

    }

This is what gets generated by the Telerik code converter,

    Public Overrides Sub OnActionExecuting(ByVal filterContext As ActionExecutingContext)

        Dim request = filterContext.HttpContext.Request
        Dim response = filterContext.HttpContext.Response

        response.Filter = New WhiteSpaceFilter(response.Filter, Function(s) Do
        s = Regex.Replace(s, "\s+", " ")
        s = Regex.Replace(s, "\s*\n\s*", vbLf)
        s = Regex.Replace(s, "\s*\>\s*\<\s*", "><")
        s = Regex.Replace(s, "<!--(.*?)-->", "")
        'Remove comments 
        ' single-line doctype must be preserved 
        Dim firstEndBracketPosition = s.IndexOf(">")
        If firstEndBracketPosition >= 0 Then
            s = s.Remove(firstEndBracketPosition, 1)
            s = s.Insert(firstEndBracketPosition, ">")
        End If
        Return s
        End Function)

    End Sub

However the Function(s) Do is invalid. I don't know how to pass a function as a parameter in a method.

Answers


It is basically a lambda expression in c#. : http://msdn.microsoft.com/en-us/library/bb397687.aspx You need to look at how to do the same in VB.net : http://msdn.microsoft.com/en-us/library/bb531253.aspx


You should be using a delegate for this in VB.NET this and this should help you.


Need Your Help

How to print nested struct objects from vector?

c++ vector struct nested

I am working on a program that keeps inventory of vehicles, so I created a struct for it. It also needs to keep a list of the drivers, so I created a nested struct for that. Here's the code:

What's a reasonably-secure, reasonably-portable way to allocate memory for private keys?

c linux unix

I'm looking for a "best practice" for allocating storage for 256-bit private keys. I'm thinking at minimum, keys shouldn't be paged to disk, and there are maybe some other attack vectors to worry ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.