c# - Can parameters be generically accessed? -


i have lot of functions this. each has n arguments , each creates sqlparamater array each paramater being of similar form.

[webmethod] public static string accessserver(string datafield1, string datafield2, string datafield3) {     string value;     sqlparamater[] param = new sqlparameter[len] // len amount of arguments     param[0] = new sqlparameter("@datafield1", datafield1);     param[1] = new sqlparameter("@datafield2", datafield2);     param[2] = new sqlparameter("@datafield3", datafield3);     ...      // param      return value; } 

this looks can done generically using combination of reflection , accessing paramaters in generic way.

ideally method of form

public static sqlparamater[] getparams(sometype paramaters)

and sqlparamater[] param = getparams(...)

i'm not sure how pass on paramaters generically.

[edit]

note names of these datafields important. it's not array of strings rather set of key/value pairs.

[/edit]

i think api design flawed if need this, better have 1 method, accepts collection of sort.

code duplication never correct way things done.

edit

on topic:

i guess can values stack: http://www.thescarms.com/dotnet/stackframe.aspx


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -