0

How do you determine whether a generic type argument is of a given type? This is what I have, but it seems hacky to instantiate the type just to test its type.

public void LogAllTheThings<T>()
    where T : class, new()
{
    if (new T() is Widget)
    {
       // Log widget-specific fields
    }
}
Anthony Faull
  • 17,549
  • 5
  • 55
  • 73

0 Answers0