I would like to have a function that modifies some variable list of parameters but they are all value types (int, string). There is a way to make the params keyword work with ref keyword or something close to that?
public void funcParams(params object[] list) { /* Make something here to change 'a', 'b' and 'c' */ } public void testParams() { int a = 1, b = 2, c = 3; funcParams(a, b, c); }
The problem is, I’m trying to make my life easier making a method that modifies the object fields. I’m doing some dynamic code generation using Cecil and I’m trying to avoid writing too much IL generated code.
To simplify I would like to pass the list of fields by reference I need to change to a function that changes them instead of changing them by generating the respective IL. Some of the parameters are nullable and make the code generation a little more painful. Making some overload methods instead of params won’t be much useful in this case.
Yes. It is possible.
However, the resulting code is ‘unsafe’ which makes it unverifiable.
That may or may not be an issue depending on your requirements.
In any case, here is the code: