c# - Map enum value robustly -
i have form collect data users. when data collected, pass various partners, each partner has own rules each piece of data, has converted. can make happen, worries robustness. here's code:
first, have enum. mapped dropdown dropdown list - description text value, , int mapped value.
public enum employmentstatustype { [description("invalid!")] none = 0, [description("permanent full-time")] fulltime = 1, [description("permanent part-time")] parttime = 2, [description("self employed")] selfemployed = 3 } when form submitted, selected value converted proper type , stored in class - property looks this:
protected virtual employmentstatustype employmentstatus { { return _application.employmentstatus; } } for final bit of jigsaw, convert value partners required string value:
dictionary<employmentstatustype, string> _employmentstatustypes; dictionary<employmentstatustype, string> employmentstatustypes { { if (_employmentstatustypes.isnull()) { _employmentstatustypes = new dictionary<employmentstatustype, string>() { { employmentstatustype.fulltime, "full time" }, { employmentstatustype.parttime, "part time" }, { employmentstatustype.selfemployed, "self employed" } }; } return _employmentstatustypes; } } string partneremploymentstatus { { return _employmentstatustypes.getvalue(employmentstatus); } } i call partneremploymentstatus, returns final output string.
any ideas how can made more robust?
then need refactor 1 translation area. visitor pattern implementation. choices distribute code (as doing now) or visitor centralize it. need build in degree of fragility covering tests show problems when extend in order force maintain code properly. in common quandry code organisational one
Comments
Post a Comment