c# - Is there more elegant method for multiple conditions verification -


case:
asp.net mvc, c# , extjs. user has got filter, can choose multiple values. there 13 such filters , user can add them or remove ui.

problem:
on server side i've got class getting filters values:

public list<string> filter1 { get; set; } public list<string> filter2 { get; set; } ... public list<string> filter13 { get; set; } 

then select data database , convert ienumerable<dataclass> dataclass looks below:

public string data1 { get; set; } public string data2 { get; set; } ... public string data13 { get; set; } 

then filter data this:

if (filter.filter1 != null && filter.filter1.any()) {     data = data.where(x => filter.filter1.contains(x.data1)); } ... if (filter.filter13 != null && filter.filter13.any()) {     data = data.where(x => filter.filter13.contains(x.data13)); } 

so there 13 if , 13 same filter logic. , code looks horrible. there way make more beautiful filter?

added: filter1 can applied data1 , on.

i create array:

private static const int n = 13;  public string[] data = new string[n]; public list<string>[] filter = new list<string>[n]; //------------------------------------------------------------------------------ for(int = 0; < n; i++) {     if(filter.filter[i] != null && filter.filter[i].any()) {         data = data.where(x => filter.filter[i].contains(x.data[i])); } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -