UZUN.NET
Cruising in .NET seas

Resharper is GREAT

Friday, 21 March 2008 11:42 by volkanuzun

Since i installed resharper ( few days ago ), i enjoy using vs 2008 more. Not only it helps me to write fast code, it also teaches me better coding :)

You wonder how ? When i have a data representing class, i always overload ==,!=, Equals, GetHashCode() functions, such as:

    public override string ToString()
        {
            return Name;
        }
        public override int GetHashCode()
        {
            return Name.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            if(obj == null)
                return false;
            Branch temp = (Branch) obj;
            return temp.Name.ToLowerInvariant().Equals(this.Name.ToLowerInvariant());
        }

        public static bool operator==(Branch d1, Branch d2)
        {
            object o1 = (object) d1;
            object o2 = (object) d2;
            if( (o1== null) ||(o2==null))
                return false;

            return d1.Equals(d2);
        }

        public static bool operator !=(Branch d1, Branch d2)
        {
            return !(d1 == d2);
        }

[/code]

 

Today while i was doing the same thing for another class, right before i was going to overload, resharper's yellow icon poped up, i hit insert enter, and resharper asked me if i want to overload members, i click sure go ahead, here is the resharper code which is a lot smarter than mine:

public bool Equals(Counselor counselor)
        {
            if (counselor == null) return false;
            return Equals(Email, counselor.Email);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj)) return true;
            return Equals(obj as Counselor);
        }

        public override int GetHashCode()
        {
            return Email != null ? Email.GetHashCode() : 0;
        }

 

[/code]

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:  
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

July 4. 2008 23:27