获取枚举witnin类类型到C#反射 [英] Getting Type of Enum witnin class through C# reflection

查看:152
本文介绍了获取枚举witnin类类型到C#反射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个枚举像

namespace EnumTest
    {
    public class Enumeration
    {
        public Enumeration();

        public enum Days
        {
           day = sunday,
           night = monday
        }
    }
}

我怎么能得到通过反射天类型的信息。

how can I get a Type Information for days through reflection.

Type type = assembly.GetType(Days);



键入类型= ty​​peof运算(天)将返回天的类型信息。如果我有无一个String =天,这个字符串s我需要得到天的类型信息。

Type type = typeof(Days) will return the Type info of Days. If I've have String s = "Days", with this string s I need to get the Type info of Days.

我需要的那种类型=天数

I need the type = Days

推荐答案

我不知道我是否理解你。如果你有一个字符串对象类型名称和想要得到的类型的对象,你需要写全类型的名称。结果
和因为你的枚举是内型完整的类型名称是EnumTest.Enumeration。 DaysEnumTest.Enumeration +天。

I'm not sure whether I understand you. If you have type name in a string object and want to get the type object you need to write the whole type name.
And because your enum is an inner type the full type name is "EnumTest.Enumeration.DaysEnumTest.Enumeration+Days".

要获得类型的对象,你可以调用然后

To get the type object you can call then

Type type = assembly.GetType("EnumTest.Enumeration.DaysEnumTest.Enumeration+Days");

这篇关于获取枚举witnin类类型到C#反射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆