0

Imagine I have the following namespace:

namespace One.Two.Three {
    public static class ExampleClass{
        public .....
        public enum ExampleOne { one, two three }
        public enum ExampleTwo { four, five, six }
        public enum ExampleThree { random, text, this, is }

    }
}

How can I get the Type by a string?

With the help of Getting Type of Enum witnin class through C# reflection I have tried the following, but without any result:

public Type returnEnumType(String name){
    String nameSpace = (typeof(One.Two.Three.ExampleClass)).FullName;
    Type type = Type.GetType(nameSpace + name);

    return type
}

Type.GetType("One.Two.Three.ExampleClass.ExampleOne"); //neither works

What am I missing here?

@edit Not a duplicate. I am not trying to parse my enumerator, I am trying to get the type based on a String.

Community
  • 1
  • 1
Revils
  • 1,478
  • 1
  • 14
  • 31

1 Answers1

2

Try Type.GetType("One.Two.Three.ExampleClass+ExampleOne");

Reason: ExampleOne is an inner type, therefore you need to use the plus sign + instead of the dot.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443