Basically, I'm wondering if I should listen to ReSharper in this instance...
You'd figure that comparing to characters one should use Char.Equals(char) since it avoids unboxing, but Resharper suggests using Object.Equals(obj). Maybe I'm missing something here?
private const DEFAULT_CHAR = '#';
// DependencyProperty backing
public Char SpecialChar
{
get { return (Char)GetValue(SpecialCharProperty); }
}
// ReSharper - Access to a static member of a type via a derived type.
if (Char.Equals(control.SpecialChar, DEFAULT_CHAR)) { ... }
I'm guessing it's because there is a DependencyProperty backing?
It is impossible to override
static
members -Object.Equals()
is a static member, andChar
cannot override it, even though you can call it on the Char type (the params are still of typeObject
)Therefore, it makes no difference whether you call
or
since boxing will occur in either case.
To avoid this, use the instance method, which is overridden in
Char
: