Is it possible to refactor this extension method?

后端 未结 6 789
小鲜肉
小鲜肉 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:24

    I like Enforce from the Lokad Shared Libraries.

    Basic syntax:

    Enforce.Arguments(() => controller, () => viewManager,() => workspace);
    

    This will throw an exception with the parameter name and type if any of the arguments is null.

提交回复
热议问题