Last active
December 21, 2015 08:29
-
-
Save takemyoxygen/6278583 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
class Foo<T> { } | |
class Bar<T> : Foo<T> { } | |
class Concrete : Bar<string> { } | |
class Another<T> : Foo<T> { } | |
static void Main(string[] args) | |
{ | |
Type genericDefinition = typeof(Concrete).BaseType.GetGenericTypeDefinition(); // Bar<> | |
Console.WriteLine(genericDefinition.Name); // Bar`1 | |
Console.WriteLine(typeof(Foo<>).IsAssignableFrom(genericDefinition)); // False. WHY?! :( | |
Console.WriteLine(genericDefinition.BaseType.Name); //Foo`1 | |
Console.WriteLine(genericDefinition.BaseType == typeof(Foo<>)); // False. WHY?! | |
Console.WriteLine(genericDefinition.BaseType.GetGenericTypeDefinition() == typeof(Foo<>)); // Finally True! | |
Console.WriteLine(typeof(Another<>).GetGenericTypeDefinition().BaseType == typeof(Bar<>).GetGenericTypeDefinition().BaseType); // False | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment