为什么ThrowIfNull
实现为:
static void ThrowIfNull<T>(this T argument, string name) where T : class
{
if (argument == null)
{
throw new ArgumentNullException(name);
}
}
改写成这样不是更好吗
static void ThrowIfNull<T>(this T argument, string name) where T : class
{
if (object.ReferenceEquals(argument, null))
{
throw new ArgumentNullException(name);
}
}
优点:它有助于避免令人困惑Equals
的重载,并且可能使代码更清晰。
有什么缺点吗?应该有一些。