DotNet Example: Working with Enumerated Types

Description

.NET enumerated types appear to be of type P in Alpha Five. Using .NET enumerated types in Xbasic, for example System::Web::HttpCookieMode, will require attention to the coding style. It is best to assign and test enumerated types as follows:

dim TestMode as System::Web::HttpCookieMode

Setting the enumerated type should be done using the static member of the type that corresponds to the value you want to set.

TestMode = System::Web::HttpCookieMode::UseCookies

Testing the value of the enumerated type should also be done using the static member of the type that corresponds to the value you want to test. You will also want to use the Equals() member of the variable to test for equivalence, as in the following interactive session.

?TestMode.Equals(System::Web::HttpCookieMode::UseCookies)
= .T.
 
? TestMode.Equals(System::Web::HttpCookieMode::AutoDetect)
= .F.

You can see the underlying integer by accessing the value__ property, or set it numerically, but these are bad practices which can turn into maintenance problems and make the code less readable.

'Note: The following are bad coding practices.
? TestMode.value__
= 2
 
TestMode = System::Web::HttpCookieMode::UseCookies
 
? TestMode.value__
= 1
 
TestMode.value__ = 0

? TestMode.value__
= 0

See Also