tags:

views:

50

answers:

2

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(CacheValidateHandler, 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?

+3  A: 

I think you need to use AddressOf:

cachePolicy.AddValidationCallback(AddressOf CacheValidateHandler, Nothing)
Anton Gogolev
+3  A: 

For passing functions as arguments in VB.NET, you have to use the AddressOf keyword:

cachePolicy.AddValidationCallback(AddressOf CacheValidateHandler, Nothing)
Arne Sostack
Thanks. That was it. Your answer was 5 seconds ahead of the next one, so I'll give you the green check.
Slack
I don't know why the Telerik converter didn't insert that. I guess the translators aren't perfect.
Slack
@Bob : Actually, he was 55 seconds ahead of me.I've recently used the Telerik converter as well. I don't think it actually looks your functions up (often it can't, if the function is in a different file). Also, when translating from VB.NET to C#, it translates indexed attributes incorrectly as array(0) rather than array[0].
Arne Sostack