Consider
public static T Get<T>(this ICache cache, string key)
{
var obj = cache.Get(key);
return (T)obj;
}
if T happens to be Guid, and obj is null (does not exist in cache), an exception occurs because Guid cannot be null. Is it possible to make Get working? I tried adding a typeof(T) == typeof(Guid)
check, but it is not possible to cast Guid into T. Puzzler!
Update @mihai, as doesn't work for me
Update2 Since Guid is not nullable, then I presume I would look for default(Guid) which is Guid.Empty. Should have put it in the original request. Thank you for everyone's contribution.