I am trying to determine what issues could be caused by using the following serialization surrogate to enable serialization of anonymous functions/delegate/lambdas.
Since this state is local though that leads to issues when trying to setup a mapping.
Wouldn't local state present the exact same problems for serialization?
Suppose the compiler and the framework allowed this to work:
Other o = FromSomeWhere();
Thing t = OtherPlace();
target.OnWhatever = () => t.DoFoo() + o.DoBar();
target.Save();
I guess t and o had to be serialized too. The methods don't have the state, the instances do.
Later, you deserialize target. Don't you get new copies of t and o? Won't these copies be out of sync with any changes to the original t and o?
Also: couldn't your manual example be called this way?
Other o = FromSomeWhere();
Thing t = OtherPlace();
target.OnWhatever = new DoFooBar() {Other = o, Thing = t} .Run;
target.Save();