Reputation: 4384
Is it possible to add a new property to an anonymous type instance after it has been initialized? I want to do something like the following:
// Initialize new object to hold subset of information about each transaction.
var transactionJson = new {};
transactionJson[transaction.Id] = new {
Status = transactionList.StatusProperty,
Completed = transactionList.Completed,
First = transactionList.First
};
Upvotes: 0
Views: 356
Reputation: 887413
That's inherently impossible.
Anonymous types are immutable, and are type-safe.
You should use a dictionary or a DynamicObject
.
Upvotes: 3