Reporter | Alex Berezoutsky (fergard) |
---|---|
Created | Jun 23, 2012 9:36:15 PM |
Updated | Apr 25, 2018 7:25:07 PM |
Subsystem | Code Analysis - Annotations |
Assignee | Alexander Shvedov (shvedov) |
Priority | Normal |
State | Open |
Type | Bug |
Fix version | Backlog |
Affected versions | 7.0 |
Fixed In Version ReSharper | Undefined |
VsVersion | All Versions |
We have the following interface:
When used in:
ReSharper complains m_Value.Serialize(stream) - Impure method is called for readonly filed of value type.
I can prevent the error by adding [Pure] to the Serialize method declaration.
But then ReSharper complains that it is ‘meaningless’ which it not really is.
The method might not be ‘Pure’ in the functional definition.
What I would need is the equivalent of the C++ const modified on methods. If .NET only had this.
[Pure] does the trick for usages and I can suppress the error in the declaration, but it shouldn’t give that error if it actually does work.
/// <summary>The Serialize method will not modify any members of the calling class.
/// The serialize interface is used to provide encode functionality to a binary stream.
/// </summary>
public interface ISerialize
{
/// <summary>
/// Serialize the current object into the supplied ByteStream instance.
/// </summary>
/// <param name="stream">The stream to be written into. The stream is always appended.</param>
void Serialize([NotNull] ByteStream stream);
}
When used in:
public class Conflict<T> : ISerialize
where T : struct, ISerialize
{
private readonly T m_Value;
public Conflict(T value)
{
m_Value = value;
}
public T Value
{
get
{
return m_Value;
}
}
public void Serialize(ByteStream stream)
{
m_Value.Serialize(stream);
}
}
ReSharper complains m_Value.Serialize(stream) - Impure method is called for readonly filed of value type.
I can prevent the error by adding [Pure] to the Serialize method declaration.
But then ReSharper complains that it is ‘meaningless’ which it not really is.
The method might not be ‘Pure’ in the functional definition.
What I would need is the equivalent of the C++ const modified on methods. If .NET only had this.
[Pure] does the trick for usages and I can suppress the error in the declaration, but it shouldn’t give that error if it actually does work.