Enums and returning primitive types

  • Thread starter Thread starter Wannabe
  • Start date Start date
W

Wannabe

public enum Panes
{
AccountSetup,
ProgramManagement,
CampaignManagement,
ProgramAccounting,
Partners,
MemberMangement,
SysAdmin
}

Accordion1.SelectedIndex = Panes.AccountSetup;

In the example above, you have to cast Panes.AccountSetup to an int so
Accordion1.SelectedIndex will accept it. I will be using this a lot and would
like to be able to do this without having to cast it everytime I use it. Is
there a way to set up a get accessor (a generic or anything) to cast it for
me? I want to be able to still type it like an enum to keep it readable.
 
Wannabe said:
public enum Panes
{
AccountSetup,
ProgramManagement,
CampaignManagement,
ProgramAccounting,
Partners,
MemberMangement,
SysAdmin
}

Accordion1.SelectedIndex = Panes.AccountSetup;

In the example above, you have to cast Panes.AccountSetup to an int so
Accordion1.SelectedIndex will accept it. I will be using this a lot and would
like to be able to do this without having to cast it everytime I use it. Is
there a way to set up a get accessor (a generic or anything) to cast it for
me? I want to be able to still type it like an enum to keep it readable.


I don't have the AJAX Controls so I can't check so see is Accordion is
sealed. If not the you could inherit Accordion control like:-

class MyAccordian : Accordion
{
// Replicate constructors you need here

public new Panes SelectedIndex
{
get { return base.SelectedIndex; }
set { base.SelectedIndex = (int)value; }
}
}

personally I think thats more trouble than its worth.

Sadly you can't add other other members to an enum, it would be nice to be
able to choose to add a implicit operator int to an enum.
 
Thanks for the reply, but you are right...that was more trouble than it is
worth. I will just stay with doing it my original way.
 
Back
Top