[238] reduant statements bug

Here two samples:

1. Sample One:

public class BaseObject : DataObject {
/// /// Initializes a new instance of the BaseObject class. /// public BaseObject() { } private int m_Id = Int32.MinValue; ///

/// Gets or sets ID. /// public virtual int Id { get { return m_Id; } set { m_Id = value; } } } [ MapTable("concrete") ] public class ConcreteObject : BaseObject { /// /// Initializes a new instance of the ConcreteObject class. /// public ConcreteObject() { } /// /// Gets or sets ID. /// [ MapField("concrete_id") ] public override int Id { get { return base.Id; } set { base.Id = value; } } } Overriden property assumed by ReSharper as reduant, but it is wrong because it uses to attach attribute that cannnot be attached at base class. 2. Sample Two: [ MapTable("concrete") ] public class ConcreteObject : BaseObject { /// /// Initializes a new instance of the ConcreteObject class. /// public ConcreteObject() { } /// /// Determines whether the specified System.Object is equal to the current System.Object. /// public override bool Equals(object obj) { ConcreteObject xx = this as ConcreteObject; ConcreteObject yy = obj as ConcreteObject; if (yy != null) { return xx.Id == yy.Id; } else { return base.Equals(obj); } } /// /// Serves as a hash function for a particular type, suitable for use in hashing algorithms /// and data structures like a hash table. /// ]]>
public override int GetHashCode() {
return base.GetHashCode();
}
}

Overriden method GetHashCode assumed by ReSharper as reduant, but it is
wrong because it uses to prevent compiler warning about using overriden
Equals without overriden GetHashCode().

1 comment
Comment actions Permalink

Hello Vlad,

In the first example ReSharper is wrong.
In the second you should override GetHashCode as
Id.GetHashCode()

Here two samples:

1. Sample One:

public class BaseObject : DataObject {
/// <summary>
/// Initializes a new instance of the BaseObject class.
/// </summary>
public BaseObject() { }
private int m_Id = Int32.MinValue;
/// <summary>
/// Gets or sets ID.
/// </summary>
public virtual int Id {
get { return m_Id; }
set { m_Id = value; }
}
}
[ MapTable("concrete") ]
public class ConcreteObject : BaseObject {
/// <summary>
/// Initializes a new instance of the ConcreteObject class.
/// </summary>
public ConcreteObject() { }
/// <summary>
/// Gets or sets ID.
/// </summary>
[ MapField("concrete_id") ]
public override int Id {
get { return base.Id; }
set { base.Id = value; }
}
}
Overriden property assumed by ReSharper as reduant, but it is wrong
because it uses to attach attribute that cannnot be attached at base
class.

2. Sample Two:

[ MapTable("concrete") ]
public class ConcreteObject : BaseObject {
/// <summary>
/// Initializes a new instance of the ConcreteObject class.
/// </summary>
public ConcreteObject() { }
/// <summary>
/// Determines whether the specified System.Object is equal to the
current System.Object.
/// </summary>
public override bool Equals(object obj) {
ConcreteObject xx = this as ConcreteObject;
ConcreteObject yy = obj as ConcreteObject;
if (yy != null) {
return xx.Id == yy.Id;
} else {
return base.Equals(obj);
}
}
/// <summary>
/// Serves as a hash function for a particular type, suitable for
use in hashing algorithms
/// and data structures like a hash table.
/// </summary>
public override int GetHashCode() {
return base.GetHashCode();
}
}
Overriden method GetHashCode assumed by ReSharper as reduant, but it
is wrong because it uses to prevent compiler warning about using
overriden Equals without overriden GetHashCode().

Thanks,
Andrey Simanovsky


0

Please sign in to leave a comment.