Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can you macro in C#/.NET?
Message
From
29/05/2012 11:49:52
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01544610
Message ID:
01544622
Views:
40
>>>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. But is there way to make it work? TIA.
>>
>>Why not just pass it as parameter?
>>
>>.....
>>Test(ParameterDirection.Input);
>>
>>public void Test(ParameterDirection TestMe)
>>        {
>>...
>>            SqlCommand sql = new SqlCommand();
>>            sql.Parameters.Add("asd", SqlDbType.Int, 4);
>>            sql.Parameters[0].Direction = TestMe;
>>   ...     
>>        }
>>
>
>You see I am passing the parameter as an array of string (in .NET all elements have to be of the same type). So the element that indicates the Direction is a string. Therefore, I need to "convert" string to the actual Direction.

Might be worth considering a Tuple:
var SqlInfo = Tuple.Create("ConnectionString", ParameterDirection.Input, CommandType.StoredProcedure);
            MakeCall(SqlInfo);
Then
void MakeCall(Tuple<string, ParameterDirection, CommandType> info)
        {
            string connection = info.Item1;
            ParameterDirection parameterDirection = info.Item2;
            CommandType commandType = info.Item3;
            //etc....
        }
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform