Remap Lookup keys in C# using LINQ -


i have lookup looking this:

lookup<string, datamodel> lookup; 

besides have dictionary containing key mappings:

dictionary<string, keymodel> keymappings; 

what want re-map string keys in lookup keymodel entities in following way:

lookup    <string, datamodel> lookup;              ||              || dictionary<string, keymodel> keymappings;             ___________|            v lookup<keymodel, datamodel> result;  

given:

dictionary<string, keymodel> keymappings = ...; ilookup<string, datamodel> lookup = ...; 

the response is:

ilookup<keymodel, datamodel> lookup2 = lookup     .selectmany(x => x, (grouping, element) => new { key = keymappings[grouping.key], element = element })     .tolookup(x => x.key, x => x.element); 

so first re-linearize ilookup<,> using selectmany, , recreate ilookup<,>.

clearly need keymodel define gethashcode() , equals(), or need iequalitycomparer<keymodel> pass parameter of tolookup()


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -