Enum String Value (deriving from a Type Name and an Integer) 
Author Message
 Enum String Value (deriving from a Type Name and an Integer)

Can anyone think of a way, in an 'Option Strict' class, to derive an
Enumeration Value from just the Name of the enumeration (as a String) and
the an Integer Value?

For instance:

  Class MyClass
      Public Enum MyEnum
        Cat = 0
        Dog = 1
      End Enum
  End Class

How could I derive the string value 'Dog' from the name 'MyClass.MyEnum' and
the value 1?

I really hope this is possible as it would be extremely useful for doing
Enum value conversions within an XSLT extension object (my primary goal).

Thanks for any ideas...
--
Phil (New Zealand - Aotearoa)



Tue, 14 Dec 2004 09:29:54 GMT  
 Enum String Value (deriving from a Type Name and an Integer)
You can use Reflection to get all all the values of the type and if the
value is what you are looking for, you can return the item name.

This will give you an Option Strict On way of performing this action.

--
Joe Feser
Fesersoft
http://www.fesersoft.com/
.Net, XML, XSLT, SQL
Free Code, Articles and Information.


Quote:
> Can anyone think of a way, in an 'Option Strict' class, to derive an
> Enumeration Value from just the Name of the enumeration (as a String) and
> the an Integer Value?

> For instance:

>   Class MyClass
>       Public Enum MyEnum
>         Cat = 0
>         Dog = 1
>       End Enum
>   End Class

> How could I derive the string value 'Dog' from the name 'MyClass.MyEnum'
and
> the value 1?

> I really hope this is possible as it would be extremely useful for doing
> Enum value conversions within an XSLT extension object (my primary goal).

> Thanks for any ideas...
> --
> Phil (New Zealand - Aotearoa)



Tue, 14 Dec 2004 11:02:15 GMT  
 Enum String Value (deriving from a Type Name and an Integer)
Nice....thats smart.
Thanks Joe.
--
Phil (New Zealand - Aotearoa)


Quote:
> You can use Reflection to get all all the values of the type and if the
> value is what you are looking for, you can return the item name.

> This will give you an Option Strict On way of performing this action.

> --
> Joe Feser
> Fesersoft
> http://www.fesersoft.com/
> .Net, XML, XSLT, SQL
> Free Code, Articles and Information.



> > Can anyone think of a way, in an 'Option Strict' class, to derive an
> > Enumeration Value from just the Name of the enumeration (as a String)
and
> > the an Integer Value?

> > For instance:

> >   Class MyClass
> >       Public Enum MyEnum
> >         Cat = 0
> >         Dog = 1
> >       End Enum
> >   End Class

> > How could I derive the string value 'Dog' from the name 'MyClass.MyEnum'
> and
> > the value 1?

> > I really hope this is possible as it would be extremely useful for doing
> > Enum value conversions within an XSLT extension object (my primary
goal).

> > Thanks for any ideas...
> > --
> > Phil (New Zealand - Aotearoa)



Tue, 14 Dec 2004 12:44:42 GMT  
 Enum String Value (deriving from a Type Name and an Integer)
Try this:

System.Enum.GetName(gettype(myEnum),1)

will return "Dog"

Regards,
Urs



Quote:
> Can anyone think of a way, in an 'Option Strict' class, to derive an
> Enumeration Value from just the Name of the enumeration (as a String) and
> the an Integer Value?

> For instance:

>   Class MyClass
>       Public Enum MyEnum
>         Cat = 0
>         Dog = 1
>       End Enum
>   End Class

> How could I derive the string value 'Dog' from the name 'MyClass.MyEnum'
and
> the value 1?

> I really hope this is possible as it would be extremely useful for doing
> Enum value conversions within an XSLT extension object (my primary goal).

> Thanks for any ideas...
> --
> Phil (New Zealand - Aotearoa)



Tue, 14 Dec 2004 19:39:51 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Retrive Enum Value if I have Enum Constant Name as a String

2. The value of a variable (String type) is the name of a variable

3. Using Enum values defined by a type library

4. HOWTO fill a listbox with ENUM type values

5. Enum of type String?

6. Assign a string value to an enum field

7. Fill combo box with enum names and values

8. Storing a 64Bits integer as a type compatible with MSAccess, but not string

9. replace a number in a string type to integer

10. Conversion from string value to long integer.

11. Converting values from strings to integers

12. Derived field names

 

 
Powered by phpBB® Forum Software