Question

Is there a way to declare a method as side-effects free using Microsoft Code Contracts (.net 4)?

Was it helpful?

Solution

The [Pure] attribute might be what you're looking for. Just attach it to your method and Code Contracts will assume it doesn't involve any state changes. Note that it doesn't actually enforce or check anything, it just tells the system to make that assumption, so it's up to you to make sure you're using it appropriately.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top