Inspired by this and this article, I\'m trying to create a dynamic function with Roslyn.
However the mentioned sources are outdated or not complete and I\'m not able
Disclaimer: I haven't actually used Roslyn in anger much at all.
Currently your code declares a variable, but doesn't do anything with it afterwards. Based on this random blog post, it looks like you possibly just need an extra expression after the declaration:
var code = @"Func<int, int> doStuffToInt = i =>
{
var result = i;
for (var y = i; y <= i * 2; y++)
{
result += y;
}
return result;
};
doStuffToInt"; // This is effectively the return statement for the script...
I don't guarantee it'll work, but give it a try :)