I created a dictionary from a Linq query result as suggested from stackoverflow questions answer: A dictionary where value is an anonymous type in C#
var intToAnon = sourceSequence.ToDictionary(
e => e.Id,
e => new { e.Column, e.Localized });
I have added this new object into my ASP.NET cache. How can I read it from the cache (HttpContext.Current.Cache.Add)? I imagine I need reflection but not sure how to go about it.
Any idea?
Thanks
To retrieve an anonymous type you’ll either need to use reflection or cast-by-example, neither of which are a good idea in this case.
Instead, either create your own custom type to hold the data, or use one of the built-in
Tupletypes:Then when you get the object from the cache just cast to the appropriate
Tupletype: