I understand that the PureAttribute
is used to mark something (class, method, delegate etc.) as making no visible changes, but I can see from the following definition that it can be applied to method parameters:
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Constructor|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Event|AttributeTargets.Parameter|AttributeTargets.Delegate, AllowMultiple = false, Inherited = true)]
public sealed class PureAttribute : Attribute
What is the purpose of this attribute being applied to a parameter, such as in the following:
public void SomeMethod([Pure]SomeClass theParameter)
{
}
Does it imply that SomeMethod
should not use anything on theParameter
which is not marked as [Pure]
, meaning we can ensure the instance of SomeClass
visibly appears the same before and after the invocation of SomeMethod
?
I have not seen the PureAttribute
used in this way and was wondering if this is due to lack of support in code contracts or because of a misunderstanding of mine?
The PureAttribute
, as you stated, indicates that a type or method is pure, that is, it does not make any visible state changes (taken straight from the MSDN article).
Maybe your SomeClass
is not marked as pure because it can change the state, however it does not mean that everything in it is impure.
Maybe your SomeMethod
doesn't use any of SomeClass
impure methods, maybe it simply reads its properties (I'm assuming you're not performing impure action in property getters, otherwise you're evil), so its usage of SomeClass
is pure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With