Created
September 15, 2012 05:18
-
-
Save kavika13/3726434 to your computer and use it in GitHub Desktop.
Enum with base type counter-example
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
using System; | |
static class Program | |
{ | |
public static void Test<TEnum>() | |
where TEnum : struct | |
{ | |
Console.WriteLine(typeof(TEnum).IsEnum); | |
} | |
public static void Test<TEnum>(this string text) | |
where TEnum : struct | |
{ | |
if (!typeof(TEnum).IsEnum) | |
{ | |
Console.WriteLine("Not an enum"); | |
return; | |
} | |
Console.WriteLine("Is an enum"); | |
} | |
public enum Test1 | |
{ | |
Value1, | |
Value2, | |
} | |
public enum Test2 : byte | |
{ | |
Value3, | |
Value4, | |
} | |
static void Main(string[] args) | |
{ | |
Test<Test1>(); | |
Test<Test2>(); | |
"".Test<Test1>(); | |
"".Test<Test2>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment