In the image above, you can see a warning from Code Contracts. I don't think this is legit, as this
can never be null
.
Is this a bug or am I missing something?
This property is a member of the following class:
public class NHibernateIQueryableQueryBase<TEntity, TQuery, TQueryInterface>
: IQuery<TEntity>, IFluentQueryInterface<TEntity, TQueryInterface>
where TQuery : NHibernateIQueryableQueryBase<TEntity, TQuery,
TQueryInterface>,
TQueryInterface
where TQueryInterface : IQuery<TEntity>
Update:
Changing the property to the following still shows the warning - on the line return result;
:
public TQueryInterface And
{
get
{
var result = this as TQuery;
return result;
}
}
The analysis doesn't understand that this
is guaranteed to implement TQuery
.
Therefore, it's warning you that you might end up taking a null
reference to the interface type, and returning it as a struct
that implements that interface:
You need to add : class
to the constraints of the TQueryInterface
parameter.