xianhc / apevolo-api

.Net 8 、SqlSugar ORM、Vue 2.X、RBAC、前后端分离的开箱则用的企业级中后台权限管理系统
https://www.apevolo.com
Apache License 2.0
809 stars 74 forks source link

Description = desc.IsNull() ? "" : ((DescriptionAttribute)desc).Description, IsNull这个有警告 #6

Closed huster-songtao closed 2 years ago

huster-songtao commented 2 years ago

AuditingFilter.cs(130,27,130,31): warning CS8604: “bool ExtObject.IsNull(object obj)”中的形参“obj”可能传入 null 引用实参。 Description = desc.IsNull() ? "" : ((DescriptionAttribute)desc).Description, desc在此处可能为null。

需要修改为: Description = desc == null ? "" : ((DescriptionAttribute)desc).Description,

或者修改为:(object加上?)

public static bool IsNotNull(this object? obj)
    {
        return obj != null;
    }

IsNull封装null的判断的确

xianhc commented 2 years ago

这是编译器问题,不需要可空类型,入参是null null!=null 自然返回false了