0
我有一個問題,我需要考慮4個布爾值的可能選項的每種組合。例如替代解決方案,如果否則如果其他樹?
我有4個布爾值,useFeatured,GROUPBY,ORDERBY &上升。可能的組合是..
featured.
featured & orderby.
featured & orderby & groupby.
featured & orderby & groupby & ascending.
featured & groupby.
featured & groupby & ascending.
featured & ascending
featured & ascedning & orderby
orderby
orderby & groupby
orderby & groupby & ascending
groupby
groupby & ascending
ascending
ascending & orderby
目前,我有一個巨大的if else如果這些選項別的樹,我覺得真的很難相信這是唯一的解決方案,但我想不出別的。
這裏是if else樹的鏈接。
if(featured){
if(orderby){
if(groupby){
if(ascedning){
//featured orderby groupby ascending
}else{
//featured orderby groupby
}
}else{
//featured orderby
}
}else if(groupby){
if(ascedning){
//featured groupby ascending
}else{
//featured groupby
}
}else if(ascending){
if(orderby){
//featured ascending orderby
}else{
//featured ascending
}
}else{
//featured
}
}else if(orderby){
if(groupby){
if(ascending){
//orderby groupby ascending
}else{
//orderby groupby
}
}
}else if(groupby){
if(ascending){
//groupby ascending
}else{
//groupvy
}
}else if(ascending){
if(orderby){
//ascending & orderby
}else{
//ascending
}
}else{
//orderby
}
Pastebin if mess messing up。 http://pastebin.com/ECgASU3C
任何人都有更好的解決方案,我可以採用?請救救我!
A [決策表(http://en.wikipedia.org/wiki/Decision_table)將是非常適合... – 2013-04-10 09:18:31
whar是你的代碼裏面的單人如果:linq-to-sql查詢? – 2013-04-10 09:20:35
這樣的東西 orderedNodeList = nodeList.OrderBy(x => x.GetPropertyValue(「featured」))。ThenByDescending(x => Convert.ToDateTime(x.GetPropertyValue(orderBy))); – user2265321 2013-04-10 09:25:24