Consider the following code:
public class AsyncRequestHandler : IHttpAsyncHandler
{
public void EndProcessRequest(IAsyncResult result)
{
if (result == null)
{
...
}
...
}
}
ReSharper suggests that result could never be null (by indicating that the condition is always false). However, since IAsyncResult is a reference type, null is a possible value. I came up with two possibilities:
- Some kind of metadata available that allows ReSharper to conclude that
resultcould never benull. Looking at theIHttpAsyncHandlersource code using ReSharper, I don't see any attributes associated withEndProcessRequest. - ReSharper is aware that the
IHttpAsyncHandlerguarantees thatIAsyncResultwill never benull. However, the documentation doesn't gives any clues either way.
It seems reasonable that IAsyncResult won't be null since it allows us to track the progress of the asynchronous task. Can someone please provide some insight?
IHttpAsyncHandleris an example of the old-style Asynchronous Programming Model.Perhaps ReSharper is designed to recognise the pattern.
Note:
So, you don't have to write code to deal with people not properly calling your code, following this pattern.