I would like to serialize classed what potentially can have properties what's current value is an anonymous function. As far as I knew this does not work out ob the box. However my very first unit test seems to be pass:
[Test]
public void AnonymousTest()
{
Func<double, double, double> func = (double a, double b) =>
{
if (a > 0) // Dummy if branch to make sure this is a delegate and not expression
{
return a + b;
}
return 0;
};
var persistedFunc = SaveAndLoad(func); // Serialize and deserialize with BinaryFormatter
Assert.AreEqual(7, persistedFunc(3, 4)); // Green
}
My question: is this working just because the deserialized delegate is running in the very same assembly, where the anonymous function exist and exist with the very same compiler generated name, or can we expect it will work in the future with the potentially changed and recompiled assembly?
EDIT: To narrow the question: Do we know at all what are the prerequisites of this is working? Say could a simple future recompile render useless the persisted state?