pauldoo
pauldoo

Reputation: 18645

How to statically verify that some C# code is functional?

When writing in a functional style in C#, 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.

Upvotes: 3

Views: 138

Answers (1)

Reality Analyst
Reality Analyst

Reputation: 77

[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.

Upvotes: 1

Related Questions