objectToCheck is Interface newVariableWithInterfaceProperties
.
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken,
RequestHandlerDelegate<TResponse> next)
{
if (request is ICacheableQuery cachableRequest)
{
// here cachableRequest now has the interface properties.
}
}
interface IItem
{
}
class ItemImp : IItem
{
}
class Program
{
static void Main(string[] args)
{
Type t = typeof(ItemImp);
Console.WriteLine("t == typeof(IItem) -> {0}", t == typeof(IItem));
Console.WriteLine("typeof(IItem).IsAssignableFrom(t) -> {0}", typeof(IItem).IsAssignableFrom(t));
Console.WriteLine("t is IItem -> {0}", t is IItem);
Console.WriteLine("new ItemImp() is IItem -> {0}", new ItemImp() is IItem);
}
}
// Here are outputs:
// t == typeof(IItem) -> False
// typeof(IItem).IsAssignableFrom(t) -> True
// t is IItem -> False
// new ItemImp() is IItem -> True