Getting Type of Enum witnin class through C# reflection

后端 未结 2 812
走了就别回头了
走了就别回头了 2021-01-21 22:01

I have a Enum like

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

        public enum Days
        {
           day          


        
2条回答
  •  遇见更好的自我
    2021-01-21 22:39

    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");
    

提交回复
热议问题