So I have this mock extension method which change a value to another value:
public static void ChangeValue(this int value, int valueToChange)
{
value = value
I know it's too late, but just for the record, I recently really wanted to do this, I mean...
someVariable.ChangeValue(10);
...apparently looks way neat than the following (which is also perfectly fine)
ChangeValue(ref someVariable, 10);
And I managed to achieve something similar by doing:
public class MyClass
{
public int ID { get; set; }
public int Name { get; set; }
}
public static void UpdateStuff(this MyClass target, int id, string name)
{
target.ID = id;
target.Name = name;
}
static void Main(string[] args)
{
var someObj = new MyClass();
someObj.UpdateStuff(301, "RandomUser002");
}
Note that if the argument passed is of reference type, it needs to be instantiated first (but not inside the extension method). Otherwise, Leri's solution should work.