You can analyze the names given to the types, just check the values for
"nameA" and "nameB":
string nameA = typeof(ClassA.EnumA).FullName;
string nameB = typeof(EnumB).FullName;
Type t1 = Type.GetType(nameA);
Type t2 = Type.GetType(nameB);
"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:3E**********************************@microsof t.com...
Using the code below, triggering new ClassB(), t1 will be null while t2
will
contain a type. What would be the proper name for EnumA?
namespace Space
{
public class ClassA
{
public enum EnumA
{
ValA1,
ValA2,
}
}
public enum EnumB
{
ValB1,
ValB2,
}
public class ClassB
{
public ClassB()
{
Type t1 = Type.GetType("Space.ClassA.EnumA");
Type t2 = Type.GetType("Space.EnumB");
}
}
}
--
Happy Coding!
Morten Wennevik [C# MVP]
"Jon Skeet [C# MVP]" wrote:
>Axel Dahmen <ke********@newsgroup.nospamwrote:
I'd like to create a generic algorithm to analyse an enum's elements
for
custom attributes. All I have at hand is is a type name to create an
enum
type info from. But if I call Type.GetType(enumTypeName) it returns
null or
throws an exception.
Can anyone enlighten me on how to walk through an unknown enums
elements to
retrieve their custom attributes?
Which assembly is the enum in? If you only specify the name,
Type.GetType will look in the current assembly and mscorlib, but that's
all.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk