我有UserInformation
檢查是否有對象屬性包含字符串
List<UserInformation> ui = new List<UserInformation>();
的UserInformation物體看起來像這樣的列表;
public class UserInformation
{
public UserInformation()
{
}
public UserInformation(UserInformation u)
{
this.Id = u.Id;
this.parentId = u.parentId;
this.Name = u.Name;
this.Title = u.Title;
this.Department = u.Department;
this.Image = u.Image;
this.Parent = u.Parent;
this.Username = u.Username;
this.Company = u.Company;
this.Initials = u.Initials;
this.Disabled = u.Disabled;
}
public int Id { get; set; }
public int? parentId { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string Department { get; set; }
public string Image { get; set; }
public string Parent { get; set; }
public string Username { get; set; }
public string Company { get; set; }
public string Initials { get; set; }
public bool Disabled { get; set; }
}
是否有某種方法來檢查這些屬性中是否包含特定的Word?可以說「.test」?
更新
我還挺想避免類似
!new[] { ".ext", ".test", ".admin" }.Any(c => ui.Title.ToLower().Contains(c))
!new[] { ".ext", ".test", ".admin" }.Any(c => ui.Department.ToLower().Contains(c))
!new[] { ".ext", ".test", ".admin" }.Any(c => ui.Company.ToLower().Contains(c))
!new[] { ".ext", ".test", ".admin" }.Any(c => ui.Username.ToLower().Contains(c))
'OBJ。屬性==「.test」'??? – Rahul
我認爲他的意思是像反射,獲取屬性和比較那些字符串類型爲「.test」。對? –
我想檢查整個'UserInformation'對象是否包含「.test」,它可以是任何包含單詞 –