I tried the following code to enable some kind of not null checking for retrieved entities to ensure they are exist before doing some concrete business:
protected T GetRequired<T>(object id)
where T : EntityObject
{
var obj = Get<T>(id);
Contract.Requires<ArgumentNullException>(obj != null);
return obj;
}
But in compile time I'm getting:
After contract block, found use of local variable 'obj' defined in contract block
Am I using Contract.Requires
in the wrong way?