Check if any property of class is null

后端 未结 3 946
深忆病人
深忆病人 2021-01-11 20:21

I have following class:-

public class Requirements
    {
        public string EventMessageUId { get; set; }
        public string ProjectId { get; set; }            


        
3条回答
  •  伪装坚强ぢ
    2021-01-11 20:41

    This might do the trick for you

    objRequirement.GetType().GetProperties()
    .Where(pi => pi.GetValue(objRequirement) is string)
    .Select(pi => (string) pi.GetValue(objRequirement))
    .Any(value => String.IsNullOrEmpty(value));
    

提交回复
热议问题