I hope I can explain my problem in a way that it s clear for everyone. We need your suggestions on this.
We have an Enum Type which has more than 15 constants defined. We receive a report from a web service and translate its one column into this Enum type. And based on what we receive from that web service, we run specific functions using Dictionary
Why am I asking for ideas? Let s say 3 of these Enum contants meet specific functions in our Dictionary but the rest use the same function. So, is there a way to add them into our Dictionary in a better way rather than adding them one by one? I also want to keep this structure because when it s time, we might have specific functions in the future for the ones that I described as "the rest".
在这里更清楚的是,我们又努力做到:
Enum:
public enum Reason{
ReasonA,
ReasonB,
ReasonC,
ReasonD,
ReasonE,
ReasonF,
ReasonG,
ReasonH,
ReasonI,
ReasonJ,
ReasonK
}
界定我们的理论:
public Dictionary<Reason, Action<CustomClassObj, string>> ReasonHandlers = new Dictionary<Reason, Action<CustomClassObj, string>>{
{ Reason.ReasonA, HandleReasonA },
{ Reason.ReasonB, HandleReasonB },
{ Reason.ReasonC, HandleReasonC },
{ Reason.ReasonD, HandleReasonGeneral },
{ Reason.ReasonE, HandleReasonGeneral },
{ Reason.ReasonF, HandleReasonGeneral },
{ Reason.ReasonG, HandleReasonGeneral },
{ Reason.ReasonH, HandleReasonGeneral },
{ Reason.ReasonI, HandleReasonGeneral },
{ Reason.ReasonJ, HandleReasonGeneral },
{ Reason.ReasonK, HandleReasonGeneral }
};
因此,基本上我所说的话是,是否有办法添加Reason, Function pair more intelligently? 因为正如你在理赔之后可以看到的那样,所有其他理由都使用同样的功能。
感谢你的建议。