本文整理汇总了C#中System.Type.IsEnum属性的典型用法代码示例。如果您正苦于以下问题:C# Type.IsEnum属性的具体用法?C# Type.IsEnum怎么用?C# Type.IsEnum使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Type
的用法示例。
在下文中一共展示了Type.IsEnum属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
public enum Color
{ Red, Blue, Green }
class TestIsEnum
{
public static void Main()
{
Type colorType = typeof(Color);
Type enumType = typeof(Enum);
Console.WriteLine("Is Color an enum? {0}.", colorType.IsEnum);
Console.WriteLine("Is Color a value type? {0}.", colorType.IsValueType);
Console.WriteLine("Is Enum an enum Type? {0}.", enumType.IsEnum);
Console.WriteLine("Is Enum a value type? {0}.", enumType.IsValueType);
}
}
输出:
Is Color an enum? True. Is Color a value type? True. Is Enum an enum type? False. Is Enum a value type? False.
示例2: Main
//引入命名空间
using System;
using System.Collections;
using System.Reflection;
public class MainClass{
public static void Main(){
Assembly LoadedAsm = Assembly.LoadFrom("yourName");
Console.WriteLine(LoadedAsm.FullName);
Type[] LoadedTypes = LoadedAsm.GetTypes();
if (LoadedTypes.Length == 0) {
Console.WriteLine("No Types!");
} else {
foreach (Type t in LoadedTypes) {
if (t.IsPublic) {
Console.WriteLine("Public ");
} else if (t.IsNestedPublic) {
Console.WriteLine("Public Nested ");
} else {
Console.WriteLine("Not Public ");
}
if (t.IsEnum) {
Console.WriteLine("Enum: ");
} else if (t.IsValueType) {
Console.WriteLine("Struct: ");
} else {
Console.WriteLine("Class: ");
}
Console.WriteLine("{0}", t.FullName);
}
}
}
}