ReSharper: how to remove “Possible 'System.NullReferenceException'” warning

后端 未结 6 1952
长情又很酷
长情又很酷 2020-12-11 02:41

Here is a piece of code:

IUser user = managerUser.GetUserById(UserId);
if ( user==null ) 
    throw new Exception(...);

Quote quote = new Quote(user.FullNam         


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 03:22

    A new answer in old post...

    Here a little sample of my code regarding how to use CodeContract via ContractAnnotation with Resharper:

        [ContractAnnotation("value:null=>true")]
        public static bool IsNullOrEmpty(this string value)
        {
            return string.IsNullOrEmpty(value);
        }
    

    It is very simple...if u find the breadcrumb in the wood. You can check other cases too.

    Have a nice day

提交回复
热议问题