Is it possible to do something like this in C#:
public void DoSomething(T t)
{
if (T is MyClass)
{
MyClass mc = (MyClass)t
Starting with C# 7, you can do this in a concise way with the is operator:
public void DoSomething(T value)
{
if (value is MyClass mc)
{
...
}
else if (value is List lmc)
{
...
}
}
See documentation: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/is#pattern-matching-with-is