using enum in model

Topics: Writing modules
Aug 17, 2011 at 10:36 PM

i wonder how i can use a enum in my model and get the mapping done to e.g int16.

has anybody any experience with that?

Aug 19, 2011 at 2:59 PM

First you would just define your enum.

public enum MyEnum
{
	Yes = 1,
	No = 2
}

Then you would add the property on your model as an int. (This is the just the ContentPartRecord.  You would obviously need the ContentPart class as well)

public class MyPartRecord : ContentPartRecord
{
	public virtual MyEnum YesNo
	{
		get;
		set;
	}
}

And finally to check that property, you would just cast your enum to an int and check it...

if(myPart.YesNo == (int)MyEnum.Yes)
{
   // Do something
}

Hope that helps,
Vinnie