这是我的代码,非常简单:
namespace EnumReflection
{
enum Messengers
{
MSN,
ICQ,
YahooChat,
GoogleTalk
}
class Program
{
static void Main(string[] args)
{
FieldInfo[] fields = typeof(Messengers).GetFields(BindingFlags.Static | BindingFlags.Public);
foreach (var field in fields)
{
Console.WriteLine(field.Name);
}
var assembly = Assembly.GetExecutingAssembly();
var type = assembly.GetType("Messengers");
Console.ReadLine();
}
}
}
但是,type
变量始终为空,即使当我说它时assembly.GetTypes()
,它也会返回所有类型,例如Messengers
, Program
。
这是我的即时窗口的副本:
assembly.GetType("Messengers");
null
assembly.GetTypes();
{System.Type[2]}
[0]: {Name = "Messengers" FullName = "EnumReflection.Messengers"}
[1]: {Name = "Program" FullName = "EnumReflection.Program"}