我在ASP.NET MVC的标记中找到了一篇关于removing whitespace的文章,然而,当我使用代码转换器时,“函数”没有正确转换
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;
});
}
}
这是Telerik代码转换器生成的内容,
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
但Function(s) Do
无效。我不知道如何将函数作为参数传递给方法。
答案 0 :(得分:3)
答案 1 :(得分:1)
它基本上是c#中的lambda表达式。 :http://msdn.microsoft.com/en-us/library/bb397687.aspx
您需要了解如何在VB.net中执行相同操作:http://msdn.microsoft.com/en-us/library/bb531253.aspx