1

I am creating a list like following:

var result = data.Select(p => new
            {
                p.FirstName,
                p.LastName,
                Relationship = p.RelationshipType,
                p.TierType,
                Gender = p.GenderType,
                p.AnnualSalary
            });

However, I need to add more properties into each of the array item of result like following

foreach(var property in ListOfAdditionalProperties)
{
  // Add property logic
}

Is this possible?

I tried ExpandoObject but was not able to come up with the final result list that I get with the Lambda mentioned on top.

RandomUser
  • 1,843
  • 8
  • 33
  • 65
  • 2
    May be it is useful. https://stackoverflow.com/questions/3934161/adding-members-to-a-dynamic-object-at-runtime – JyothiJ Mar 22 '18 at 10:14

1 Answers1

0

No, it's not possible.

You cannot add more members to a dynamic type after the type has been created. Think of it as a class declaration. Once the class is declared and compiled it cannot be modified.

You need to use another approach, just like the ones you mention. But yes, that has it's drawbacks in regards to syntax.

Adam B
  • 506
  • 1
  • 5
  • 13