views:

111

answers:

2

Does it do anything at all or it is only for documentation. If it is only for documentation, why documentation doesn't document it?

For example these are two methods from System.Array class:

[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
public static void Copy(Array sourceArray, Array destinationArray, int length)

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static void ConstrainedCopy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)

However documentation doesn't even mention that Copy or ConstrainedCopy are decorated.

+1  A: 

From MSDN:

The ReliabilityContractAttribute attribute provides a mechanism for you to document your code, and to indicate what type of reliability guarantees you can make in the face of exceptional conditions that could potentially lead to an inconsistent state. In this context, exceptional conditions are defined as asynchronous exceptions that can be generated at run time by the common language runtime, such as aborted threads, out-of-memory situations, and stack overflows. You can apply the ReliabilityContractAttribute attribute to assemblies, types, and methods.

Use this attribute with the Consistency enumeration to define a reliability contract by documenting the level of reliability in a particular piece of code.

Andrew Hare
Yes. I have read this. So, why this documentation is ignored?
Prankster
+1  A: 

I believe they're used for constrained execution regions too, so the CLR knows what it can do safely.

See this MSDN magazine article on .NET reliability features for a lot more information.

Jon Skeet
Yep. This is it.
Prankster