c# - Accessing variable from string name -


i accessing variable der, can or set through local _der.

the setvalues gets string name on parameter wanted change(and list local list should set to)

the string comes "global" datastore name, change local (der->_der).

now, how in setvalues, "convert" string name lparam, actual local parameter want set?

hope u understand , can

[subscribe] public storablelist<double> der{     get{return _der;}     set{_der = value;} }  public static string converttolocalparameter(string input) {     if (string.isnullorempty(input)) {         throw new argumentexception("argh");     }      return "_" + char.tolower(input[0]) + input.substring(1); }  public void setvalues(string listname, storablelist<double> values) {     string lparam = converttolocalparameter(listname); }  private storablelist<double> _der; 

if understand correct (and java), use reflection

field field = myclass.class.getdeclaredfield(lparam);  field.set(this, values); 

but if have limited amount of such values use few if's in method set value


edit: if it's c#, can read reflection in c#


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -