Is it possible to refactor this extension method?

后端 未结 6 795
小鲜肉
小鲜肉 2020-12-24 07:40

I have the following extension method:

public static void ThrowIfArgumentIsNull(this T value, string argument) 
    where T : class
{
    if (value          


        
6条回答
  •  庸人自扰
    2020-12-24 08:19

    I would recommend that you rather do the following:

    public static void ThrowIfArgumentIsNull(this object value, string argument) 
    {
        if (value == null)
        {
            throw new ArgumentNullException(argument);
        }
    }
    

    Using generics in this case doesn't seem to add any value. But as to your original question, I don't think that's possible.

提交回复
热议问题