Is there a way to declare a method as side-effects free using Microsoft Code Contracts (.net 4)?
Asked
Active
Viewed 53 times
0
-
Did you look into the "Preconditions" section of http://msdn.microsoft.com/en-us/library/dd264808.aspx ? – Intermernet May 21 '13 at 13:24
1 Answers
2
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.

Jeremy Todd
- 3,261
- 1
- 18
- 17