Код: Выделить всё
public class Class1
{
public int Int1;
public int Int2;
public int Int3;
public int GetInt(string name)
{
return GetType().GetField(name).GetValue(this); // or use a switch expression
}
public void SetInt(string name, int value)
{
GetType().GetField(name).SetValue(this, value); // or use a switch statement
}
}
public class Class2
{
public Class1 Container;
public void DoStuff()
{
Class3.DoSomething(ref Container.Int1);
Class3.DoSomething(ref Container.Int2);
Class3.DoSomething(ref Container.Int3);
}
}
public class Class3
{
public static void DoSomething(ref int thing)
{
// ...
}
}
Код: Выделить всё
public void DoStuffMonitored()
{
int local;
{
local = Container.GetInt("Int1");
Class3.DoSomething(ref local);
Container.SetInt("Int1", local);
}
{
local = Container.GetInt("Int2");
Class3.DoSomething(ref local);
Container.SetInt("Int2", local);
}
{
local = Container.GetInt("Int3");
Class3.DoSomething(ref local);
Container.SetInt("Int3", local);
}
}
РЕДАКТИРОВАТЬ: Это однопоточная среда.
Для большего контекста все эти классы взяты из сборки, которой я не владею, но для изменения я использую Mono.Cecil время выполнения.
Подробнее здесь: https://stackoverflow.com/questions/797 ... -arguments
Мобильная версия