新增对象是否为null的检测方法IsNull和IsNotNull
This commit is contained in:
parent
8cf7880575
commit
02c2c8843e
|
@ -87,6 +87,28 @@ namespace Falcon.SugarApi.Test
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为空测试
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void IsNullTest() {
|
||||
object obj = null;
|
||||
Assert.IsTrue(obj.IsNull());
|
||||
Assert.IsFalse(obj.IsNotNull());
|
||||
|
||||
obj=new object();
|
||||
Assert.IsTrue(obj.IsNotNull());
|
||||
Assert.IsFalse(obj.IsNull());
|
||||
|
||||
object? obj1 = null;
|
||||
Assert.IsTrue(obj1.IsNull());
|
||||
Assert.IsFalse(obj1.IsNotNull());
|
||||
|
||||
obj1=new object();
|
||||
Assert.IsTrue(obj1.IsNotNull());
|
||||
Assert.IsFalse(obj1.IsNull());
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 扩展属性测试类
|
||||
|
|
|
@ -90,6 +90,20 @@ namespace Falcon.SugarApi
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对象是否为null
|
||||
/// </summary>
|
||||
/// <param name="obj">要测试的对象</param>
|
||||
/// <returns>True表示对象为null,否则不为null</returns>
|
||||
public static bool IsNull([AllowNull] this object obj) => obj==null;
|
||||
|
||||
/// <summary>
|
||||
/// 对象是否不为null。与IsNull相反
|
||||
/// </summary>
|
||||
/// <param name="obj">要测试的对象</param>
|
||||
/// <returns>True表示对象不为null,否则为null</returns>
|
||||
public static bool IsNotNull([AllowNull] this object obj) => !obj.IsNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue
Block a user