Connecting Tech Pros Worldwide Forums | Help | Site Map

Enums and returning primitive types

=?Utf-8?B?V2FubmFiZQ==?=
Guest
 
Posts: n/a
#1: Aug 28 '08
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.


Anthony Jones
Guest
 
Posts: n/a
#2: Aug 28 '08

re: Enums and returning primitive types


"Wannabe" <Wannabe@discussions.microsoft.comwrote in message
news:988D8D1A-5A71-4293-8A6D-9D8A92EBF205@microsoft.com...
Quote:
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
Quote:
like to be able to do this without having to cast it everytime I use it.
Is
Quote:
there a way to set up a get accessor (a generic or anything) to cast it
for
Quote:
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.




--
Anthony Jones - MVP ASP/ASP.NET


=?Utf-8?B?V2FubmFiZQ==?=
Guest
 
Posts: n/a
#3: Aug 28 '08

re: Enums and returning primitive types


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.

"Anthony Jones" wrote:
Quote:
"Wannabe" <Wannabe@discussions.microsoft.comwrote in message
news:988D8D1A-5A71-4293-8A6D-9D8A92EBF205@microsoft.com...
Quote:
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
Quote:
like to be able to do this without having to cast it everytime I use it.
Is
Quote:
there a way to set up a get accessor (a generic or anything) to cast it
for
Quote:
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.
>
>
>
>
--
Anthony Jones - MVP ASP/ASP.NET
>
>
>
Closed Thread


Similar ASP.NET bytes