When I use SlSvcUtil.exe to create my service client files, I see code like this:
private string CategoryField;
[System.Runtime.Serialization.DataMemberAttribute()]
public string Category
{
get
{
return this.CategoryField;
}
set
{
if ((object.ReferenceEquals(this.CategoryField, value) != true))
{
this.CategoryField = value;
this.RaisePropertyChanged("Category");
}
}
}
When I inspect it with ReSharper, I receive the following warning:
'Object.ReferenceEquals' is always false because it is called with a value type
I understand that strings are immutable, but I seem to receive this warning for every property.
ReSharper recommends the following:
Note: This includes my custom styling of putting simple getters on one line, inverting the if
, removing the redundant object
qualifier and the != true
comparison
private string CategoryField;
[DataMember]
public string Category
{
get { return this.CategoryField; }
set
{
if (Equals(this.CategoryField, value)) { return; }
this.CategoryField = value;
this.RaisePropertyChanged("Category");
}
}
So it really begs the question, why does SlSvcUtil.exe use ReferenceEquals
instead of Equals
if ReferenceEquals
is always going to return false?