Wrap Sub as Function for use in Lambda
        Posted  
        
            by Luhmann
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Luhmann
        
        
        
        Published on 2010-03-25T09:11:28Z
        Indexed on 
            2010/03/25
            9:13 UTC
        
        
        Read the original article
        Hit count: 214
        
I have a problem with VB and Moq.
I need to call a verify on a Sub. Like so:
logger.Verify(Function(x) x.Log, Times.AtLeastOnce)
And my logger looks like this:
Public Interface ILogger
    Sub Log()
End Interface
But with VB this is not possible, because the Log method is a Sub, and thereby does not produce a value.
I don't want to change the method to be a function.
Whats the cleanest way of working around this limitation and is there any way to wrap the Sub as a Function like the below?
logger.Verify(Function(x) ToFunc(AddressOf x.Log))
I have tried this, but i get:
Lambda Parameter not in scope
© Stack Overflow or respective owner