Hi
Given the following code example
// Method declaration
private bool ValidRequest(RequestBase request, ResponseBase response, Validate validate)
// Condition statement
if ((Validate.ClientTag & validate) == Validate.ClientTag)
Validate is an Enum with a variable ClientTag that has a value of 0x0001 assigned.
Am I right in saying that given Validate.ClientTag is an Enum, the assignment operator cannot be used to Set the input parameter validate. As a result the & operator needs to be used instead?
In addition the expression (Validate.ClientTag & validate) has to be encapsulated into its own parenthesis within the if statement due to the mismatch of types ClientTag and bool?
Thanks
Loading
VulpesPosted Mar 17, 2012, 4:18 PM
VulpesPosted Mar 18, 2012, 5:48 PM
You can in fact use ANY value of the underlying type (usually int) as an enum value, whether it corresponds with one of the defined values or not, simply by casting it to the enum type. However, this is normally poor programming practice and you should therefore stick to only assigning defined values to an enum variable.
The request 'parameter' is of type RequestBase which I don't know anything about but it evidently has a ClientTag property of type string because "ABC123" is a string.
Guest UserPosted Mar 18, 2012, 4:48 PM
Further to your previous reply. Could you kindly answer another related question please.
The Validate Enum has the following variables and values:-
ClientTag = 0x0001,
AccessToken = 0x0002,
UserCredentials = 0x0004,
All = ClientTag | AccessToken | UserCredentials
Under the ValidRequest method declaration the first if statement looks like the one I showed previously ie
if ((Validate.ClientTag & validate) == Validate.ClientTag)
it then has another if statement as follows:-
if (request.ClientTag != "ABC123")
the value "ABC123" is declared in a Web.Config file
There is another 2 declarations for the AccessToken and UserCredentials flags.
My questions are:-
Does the above still fit in with what you replied with?
What type of value should I expect to see passed into the input parameter (Validate validate) I assume it could be anything?
Are the values to each Enum variable simply just values that have no relation with the value that validate will receive?
Thanks
Guest UserPosted Mar 18, 2012, 7:04 AM
Thanks kindly Vulpes