0

I have an UGLY logic tree that I'm looking at ways replace with some code generated from a table. It branches based on several thing:

  • the length of a List<AbstractType>
  • the actual types in the list
  • a flags enum

My basic idea is to build some kind of decision tree from by input table. For the list length and flags that's easy (a switch), but what about the types bit?

This question suggests that polymorphism is a good idea but that would mix concerns and strew code to the four winds in my case (and doesn't lend its self to generation anyway). The other suggested solution (IDictionary<Type, DelegateType>) might work but seem a little ugly.

Does anyone have any suggestions.

4

1 回答 1

1

一种方法是连接类型名称(例如用冒号分隔),然后通过字符串切换,例如

 switch(colon_separated_typenames(list)) {
   case "int:int": //foo
   case "double:String:double": //bar
 }
于 2009-08-15T18:43:53.870 回答