How to port C# code which uses a callback to VB.NET?
I need to port the following from the ASP.NET MVC 2 sourcecode from C# to VB.NET. It's from AuthorizeAttribute.cs beginning on line 86:
HttpCachePolicyBase cachePolicy = filterContext.HttpContext.Response.Cache;
cachePolicy.SetProxyMaxAge(new TimeSpan(0));
cachePolicy.AddValidationCallback(CacheValid开发者_开发问答ateHandler, null /* data */);
where CacheValidateHandler is:
private void CacheValidateHandler(HttpContext context, object data,
ref HttpValidationStatus validationStatus) {
validationStatus = OnCacheAuthorization(new HttpContextWrapper(context));
}
The VB.NET port from http://converter.telerik.com doesn't quite work for this line:
cachePolicy.AddValidationCallback(CacheValidateHandler, Nothing) ' Error
where CacheValidateHandler is:
Private Sub CacheValidateHandler(ByVal context As HttpContext, ByVal data As Object, _
ByRef validationStatus As HttpValidationStatus)
validationStatus = OnCacheAuthorization(New HttpContextWrapper(context))
End Sub
VS2008 complains that CacheValidateHandler does not specify its arguments for context, data, and validationStatus.
Any ideas how to port this code?
For passing functions as arguments in VB.NET, you have to use the AddressOf keyword:
cachePolicy.AddValidationCallback(AddressOf CacheValidateHandler, Nothing)
I think you need to use AddressOf
:
cachePolicy.AddValidationCallback(AddressOf CacheValidateHandler, Nothing)
精彩评论