How to statically verify that some C# code is functional?
When writing in a functional style in C开发者_StackOverflow#, are there any tools to statically verify that classes are immutable and functions are pure? I imagine it to be impossible in the general case, but a tool that's right 90% of the time would still be useful.
I can imagine some reflection that checks that all member variables are readonly
, and that all member types (and all visible subtypes) are also immutable (recursively). I've no idea how the check on functions would begin to operate.
[Immutable] and [Pure] annotations seem to be geared towards this. Take a look at Design by Contract tools for .NET 4.0. IIRC, static verification only works with VS Ultimate, though.
精彩评论