Getting Enum value via reflection

前端 未结 15 2532
梦如初夏
梦如初夏 2020-12-05 01:35

I have a simple Enum

 public enum TestEnum
 {
     TestOne = 3,
     TestTwo = 4
 }

var testing = TestEnum.TestOne;

And I want to retrieve

15条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 02:31

    In my case, the problem was MyEnum not been found due to a + sign getting type from assembly (line 2):

    var dll = System.Reflection.Assembly.LoadFile("pathToDll");
    Type myEnum = dll.GetType("namespace+MyEnum");
    System.Array myEnumValues = System.Enum.GetValues(myEnum);
    

提交回复
热议问题