So say we have loaded a function F
that take in/out a set of args
and returns a result
. How to check at runtime if this F
does not act on anything other than args
members and functions? Meaning no Console.Writeline
, Singletons (or other stuff not presented in args
). Is it possible with CodeContracts
library or some other solution?
Say we know that [Pure]
attribute was presented in the function definition. This sucks for many cases when we have a lambda, yet at least it would be something
Why I do not see how [Pure]
can help - this code compiles:
class Test {
public struct Message {
public string Data;
}
public struct Package {
public int Size;
}
[Pure]
public static List<Package> Decomposse(Message m) {
Console.WriteLine("rrrr"); // This sould not happen
var mtu = 1400;
Package p = new Package{Size = mtu};
return Enumerable.Repeat(p, m.Data.Length / mtu).ToList();
}
}
And I want to eliminate (or at least detect that function calls stuff like Console.WriteLine("rrrr")
)