File tree Expand file tree Collapse file tree
GameFrameX.Foundation.Extensions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,21 +15,31 @@ namespace GameFrameX.Foundation.Extensions;
1515public static class ObjectExtensions
1616{
1717 /// <summary>
18- /// 检查对象是否为null
18+ /// 检查引用类型对象是否为null
1919 /// </summary>
20+ /// <typeparam name="T">对象的类型,必须为引用类型</typeparam>
2021 /// <param name="self">要检查的对象</param>
2122 /// <returns>如果对象为null,则返回true;否则返回false</returns>
22- public static bool IsNull ( this object self )
23+ /// <remarks>
24+ /// 此方法仅适用于引用类型,对值类型调用此方法会导致编译错误。
25+ /// 这是为了避免对值类型(永远不会为null)调用此方法产生误导性结果。
26+ /// </remarks>
27+ public static bool IsNull < T > ( this T self ) where T : class
2328 {
2429 return self is null ;
2530 }
2631
2732 /// <summary>
28- /// 检查对象是否不为null
33+ /// 检查引用类型对象是否不为null
2934 /// </summary>
35+ /// <typeparam name="T">对象的类型,必须为引用类型</typeparam>
3036 /// <param name="self">要检查的对象</param>
3137 /// <returns>如果对象不为null,则返回true;否则返回false</returns>
32- public static bool IsNotNull ( this object self )
38+ /// <remarks>
39+ /// 此方法仅适用于引用类型,对值类型调用此方法会导致编译错误。
40+ /// 这是为了避免对值类型(永远不会为null)调用此方法产生误导性结果。
41+ /// </remarks>
42+ public static bool IsNotNull < T > ( this T self ) where T : class
3343 {
3444 return self is not null ;
3545 }
You can’t perform that action at this time.
0 commit comments