dictionary - Is it possible to have value type based on the key on key/value pair in C#? -
let me give simple example better understanding of question
library holds:
enum keys { [description("color select")] colorselection, [description("day select")] dayselection, [description("gender select")] genderselection } enum color { [description("white color")] white, [description("black color")] black, [description("brown color")] brown } enum day { [description("monday")] monday, [description("tueday")] tuesday, [description("wednesday")] wednesday } enum gender { [description("male gender")] male, [description("female gender")] female }
from client want this:
dictionary<keys, ??> values = new dictionary<keys, ??>(); values.add(keys.colorselection, <auto suggest color>); values.add(keys.dayselection, <auto suggest day>);
i'm okay modify library have list of values
enum
but, want client auto suggest values filters based on key.
note:
1. don't want class(model) property respective type since there lot of keys available in library , client pick few , provide values.
2. cannot have values alone list<values>
since cases have same description
value different key.. eg: "yes/no values same different keys"
any suggestions? in advance..
you declare dictionary as:
var dictionary = new dictionary<keys, int>();
and encapsulate in own custom class method uses keys value of key interpret value using corresponding enum.
the whole problem here seems code smell though.
Comments
Post a Comment