Wednesday, August 24, 2005

enumerations and the design time experience

I get this question a lot

My control has an enum declared but fequently I get an error message like "The variable 'yourenumtypehere' is either undeclared or was never assigned." that blows out my control from the design surface. Why?

Doing lots of .net GUI controls you start to learn a few things. One of the thing's I've found over time is that the designer HATES enumerations that are declared inside classes. For some reason it serializes at times and doesn't at other times. Therefore, to fix this, simply delcare your enumerations outside any class in the namespace.

for example

namespace MyNameSpace
{
// good enum declaration
public enum GoodEnum
{
Good,
Better
}

public class TestClass
{
public enum BadEnum
{
Bad,
Worse
}
}
}

No comments: