>>>Hi,
>>>
>>>Before I do the IF/ELSE, or SWITCH, I am wondering if I could macro expand in C#. Here is an example. I am passing a value of ParameterDirection as a string (e.g. 'Input', 'InputOutput', 'Output') I need to set ParameterDirection based on the passed value.
>>>
>>>Here is the pseudo code:
>>>
>>>
>>>string cDirection = 'Input';
>>>param.Direction = ParameterDirection. + 'cDirection';
>>>
>>>
>>>I am pretty sure that the above syntax will not work.
>>
>>It won't :-}
>>
>> But is there way to make it work?
>>
>>In general, no. But for enums you can use this:
string cDirection = "Input";
>>param.Direction= (ParameterDirection) Enum.Parse(typeof(ParameterDirection), cDirection);
>
>Thank you. I will try this approach.
Using the enum directly is shorter
param.Direction = ParameterDirection.Input;
Gregory