Is there a way to concat C# anonymous types? -


for example

var hello = new { hello = "hello" }; var world = new { world = "world" }; var helloworld = hello + world; console.writeline(helloworld.tostring()); //outputs {hello = hello, world = world} 

is there way make work?

no. hello , world objects objects of different classes.

the way merge these classes use dynamic type generation (emit). here example of such concatenation: http://www.developmentalmadness.com/archive/2008/02/12/extend-anonymous-types-using.aspx

quote mentioned article:

the process works this: first use system.componentmodel.getproperties propertydescriptorcollection anonymous type. fire reflection.emit create new dynamic assembly , use typebuilder create new type composite of properties involved. cache new type reuse don't have take hit of building new type every time need it.


Comments

Popular posts from this blog

php - How to build a web site which gives a sub-domain dynamically to every registered user? -

android - View with visibility state GONE taking up space on screen -