anonymous-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 ...

Add property to anonymous type after creation

I use an anonymous object to pass my Html Attributes to some helper methods. If the consumer didn't add an ID attribute, I want to add it in my helper method. How can I add an attribute to this anonymous object? ...

What to use: var or object name type?

this is a question that when programming I always wonder: What to use when we are writting code: var myFiles = Directory.GetFiles(fullPath); or string[] myFiles = Directory.GetFiles(fullPath); var is new and is a Implicitly Typed Local Variables, so we can only used locally and it has rules like can't be null, etc., but I wonder i...

How can I access the properties of an anonymous object?

$.post("test.php", { name: "John", time: "2pm" }, function(data){ alert("Data Loaded: " + data); }); The object { name: "John", time: "2pm" } is anonymous. Normally, I would access the properties of an object using syntax similar to the following: objectname.propertyname But what can I do when there is no objectname? How can...

How do I access the parent Object of an anonymous object in Java?

this.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { // How do I access the parent tree from here? } }); ...

JavaScript check if anonymous object has a method

How can I check if an anonymous object that was created as such: var myObj = { prop1: 'no', prop2: function () { return false; } } does indeed have a prop2 defined? prop2 will always be defined as a function, but for some objects it is not required and will not be defined. I tried what was su...

Is it possible to load a UserControl into an anonymous object, instead of just instantiating it?

Currently I'm generating UserControls as follows in an abstract base class so they are available for any other pages that implement the base class: // doc is an XML file that may or may not contain a TopStrapline node var pageControls = new { TopStrapline = (from strap in doc.Elements("TopStrapline") ...