[Mono-dev] [CODE] Implementation of DisplayNameAttribute in System.ComponentModel

Sebastien Pouliot sebastien.pouliot at gmail.com
Fri Nov 10 09:03:24 EST 2006

Hello Marek,

On Fri, 2006-11-10 at 13:06 +0100, Marek Habersack wrote:
> Hello,
>   I've implemented the missing class named in the subject. The source
> code is attached. May I commit?

Please supply unit tests with new classes. You'll find some bugs by
doing so (mostly your own ;-) but sometime bugs in existing code too)
and, often, will see that the MSDN documentation is out of date (or

                public override bool IsDefaultAttribute ()
                        return attributeDisplayName == String.Empty;

return (attributeDisplayName.Length == 0);
is faster (and would be a nice rule for Gendarme too ;-)

                public override int GetHashCode ()
                        return attributeDisplayName.GetHashCode ();

in your (ctor) code attributeDisplayName can be null (not sure if MS
allows that or not), which means GetHashCode will throw a NRE
                public override bool Equals (object obj)
                        if (!(obj is DisplayNameAttribute))
                                return false;
                        if (obj == this)
                                return true;
                        return ((DisplayNameAttribute)obj).DisplayName
== attributeDisplayName;
Here you're doing two casts. You can do the same with a single cast.

                public virtual string DisplayName
                        get { return attributeDisplayName; }
                protected string DisplayNameValue
                        get { return attributeDisplayName; }
                        set { attributeDisplayName = value; }

same comment as the ctor, can null be assigned to attributeDisplayName ?
if so will DisplayName/DisplayNameValue return null (get) or the default
String.Empty ?


More information about the Mono-devel-list mailing list