A Henry P. Erich III Blog

A Geek In and Around Orlando

<December 2008>
SuMoTuWeThFrSa
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910


Navigation

Links

Subscriptions



Wednesday, April 07, 2004 - Posts

A Way to Validate an Enum Passed in a QueryString

// Declare a variable that you want to store your validated

// enum value in.

CommandBehavior cmdBehavior;

try

{

// Validate the enum with a try/catch

string cmdBehaviorRequest = Request.QueryString["cmdBehavior"];

cmdBehavior = (cmdBehavior)Enum.Parse(typeof(cmdBehavior), cmdBehaviorRequest, true);

}

catch

{

// Set to default or whatever other handling you want.

cmdBehavior = DEFAULT_CMD_BEHAVIOR;

}

posted Wednesday, April 07, 2004 1:02 PM by he3 with 2 Comments




Powered by Dot Net Junkies, by Telligent Systems