c# - Dictionary of generic lists or varying types -


i want have dictionary maps strings generic lists of varying types. i.e. in following form:

 key        value string     list<t> string     list<u> string     list<v> string     list<u> ... 

currently i'm using dictionary<string, ilist> , extracted typed list each dictionary keyvaluepair<string, ilist> pair entry follows:

type layertype = pair.value.gettype().getgenericarguments()[0]; list<layertype> objectsclicked = pair.value list<layertype>; 

is there nicer way this?

[edit] has been noted, above doesn't compile, apologies - that's when ask question while you're still working on somethings. more explanation. i'm making basic spatial data viewer. final view consists of group of layer<t>s. each layer provides delegate render type (given offset , scale) , way check of objects in current window. hit testing, list each layer of objects have been hit. list list<point> point layer, etc... grouping of hits layer<t>s collection of typed lists.

how dictionary<string, dynamic> assuming you're on c# 4

dictionary<string, dynamic> dict = new dictionary<string, dynamic>(); dict.add("int", new list<int>()); dict.add("string", new list<string>());  dict["int"].add(12); dict["string"].add("str");  foreach (keyvaluepair<string, dynamic> pair in dict) {    type t = pair.value.gettype();    console.writeline(t.getgenericarguments()[0].tostring()); } 

that prints out

system.int32

system.string

is you're looking for?


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -