Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is resharper making the following recommendation?

Tags:

c#

resharper

My code is...

public static void AssertNotNull<T>(string name, T val) {
    if (val == null)
        throw new ArgumentNullException(String.Format("{0} must not be null", name));
}

Resharper is recommending...

public static void AssertNotNull<T>(string name, T val) {
    if (Equals(val, default(T)))
        throw new ArgumentNullException(String.Format("{0} must not be null", name));
}
like image 641
JeremyWeir Avatar asked Feb 26 '09 19:02

JeremyWeir


1 Answers

Because it doesn't know if T is a value type or reference type, so it makes the code work with both.

like image 76
Beardo Avatar answered Dec 04 '22 21:12

Beardo