c# - Add property without naming existing properties by Linq -


in linq how can add new properties besides other existing properties without mention them.

for example have class myclass:

public class myclass {    public int p1 {get; set;}    public int p2 {get; set;} } 

and @ runtime:

list<myclass> list = // myclass objects list ... 

and wrapperlist has 3 more new properties

var wrapperlist = list.select(m=> new {   p1 = m.p1  // don't want   p2 = m.p2  // don't want   newp1 = somenewval1   newp2 = somenewval2   newp3 = somenewval3 }); 

notice don't using new wrapper class new properties subclass of myclass , myclass object constructor argument or thing this, because wrapper class general class , has fixed properties (newp1 ,newp2 ,newp3) , designed wrap kind of objects (for example myclass). kind of solutions causes have modifications in myclass definition unacceptable.

update: wrapper class anonymous object has been created @ runtime inside select extension method.

would work you?

var wrapperlist = list.select(m => new {     wrappedobject = m,     newp1 = somenewval1,     newp2 = somenewval2,     newp3 = somenewval3 }); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -