Search code examples
c#silverlightreflectionanonymous-objects

Create anonymous object by Reflection in C#


Is there any way to create C# 3.0 anonymous object via Reflection at runtime in .NET 3.5? I'd like to support them in my serialization scheme, so I need a way to manipulate them programmatically.

edited later to clarify the use case

An extra constraint is that I will be running all of it inside a Silverlight app, so extra runtimes are not an option, and not sure how generating code on the fly will work.


Solution

  • Here is another way, seems more direct.

    object anon = Activator.CreateInstance(existingObject.GetType());