Questions tagged [expandoobject]

ExpandoObject is a .NET type whose members can be added and removed at runtime.

From msdn: Represents an object whose members can be dynamically added and removed at run time.

Instances are typically declared with the dynamic keyword:

dynamic sampleObject = new ExpandoObject();

This type is part of System.Dynamic and was introduced with .NET 4.

356 questions
4
votes
3 answers

Why does LINQ not work to add DataRows to a DataTable?

To shoehorn ExpandoObjects into something grids like the following two attempts were made. This doesn't work: var data = _d.Query(_script); // returns IEnumerable IDictionary c = (IDictionary
Guy--L
  • 170
  • 2
  • 13
4
votes
1 answer

How do I reference a field in an ExpandoObject dynamically?

Is there a way to dynamically access the property of an expando using a "IDictionary" style lookup? var messageLocation = "Message"; dynamic expando = new ExpandoObject(); expando.Message = "I am…
ScArcher2
  • 85,501
  • 44
  • 121
  • 160
4
votes
1 answer

Serialize instance of a class deriving from DynamicObject class

I have a class that derives from DynamicObject class. On calling JsonConvert.SertializeObject, none of the dynamic properties are serialized. Class is defined as, public class Component : DynamicObject { // The inner…
Usman Khan
  • 139
  • 2
  • 12
4
votes
0 answers

pros/cons of returning dynamic object from asp.net web api 2

I am building a asp.net web api 2 service. I need to create multiple endpoints. The service only returns data. I have around 200 end points & every end point return different type of data. I do not want to create multiple models representing each…
SharpCoder
  • 18,279
  • 43
  • 153
  • 249
4
votes
1 answer

ExpandoObject object and GetProperty()

I'm trying to write a generic utility for use via COM from outside .NET (/skip long story). Anyway, I'm trying to add properties to an ExpandoObject and I need to get PropertyInfo structure back to pass to another routine. using…
Rob Spencer
  • 77
  • 1
  • 7
4
votes
1 answer

How to XML serialize an ExpandoObject into property/value pairs?

I'm intercepting a Web API 2 pipeline at the call to OnActionExecuted. Here, I'm turning the object returned by the action into an ExpandoObject, recursively (i.e any properties on the object that are themselves objects also get turned into…
MiloDC
  • 2,373
  • 1
  • 16
  • 25
4
votes
0 answers

Binding behavior to dynamic object differs between WPF and WinRT

I am trying to data bind a Xaml property to a property of a dynamic object. In this case the dynamic object is a JObject from the Json.Net library. JObject is a well behaved dynamic object and I've had no problems with it in the past. It makes for a…
dkackman
  • 15,179
  • 13
  • 69
  • 123
4
votes
1 answer

JSON array to ExpandoObject via JSON.NET

I am using the following approach to convert most of my API JSON results into an object: public void ExpandoObject() { var sampleDATA = Sample.Create(); var json = JsonConvert.SerializeObject(sampleDATA); var expConverter = new…
RealityDysfunction
  • 2,609
  • 3
  • 26
  • 53
4
votes
1 answer

Access DynamicModel.Query using dot notation or index

I am using Massive micro-orm and SQL server 2008R2 with .NET framework 4.0. // This is my model public class sUser : DynamicModel { public sUser() : base(Model.strConnection, "Users", "UserId") { } } and another class... using…
Rajul
  • 135
  • 10
4
votes
2 answers

TPL Tasks + dynamic == OutOfMemoryException?

I'm working on a streaming twitter client- after 1-2 days of constant running, I'm getting memory usage of >1.4gigs (32 bit process) and soon after it hits that amount, I'll get an out of memory exception on code that's essentially this (this code…
dethSwatch
  • 1,152
  • 1
  • 10
  • 18
4
votes
1 answer

Binding ExpandoObject in Silverlight

In WPF, you can bind against ExpandoObject and other dynamic types: dynamic o = new ExpandoObject(); o.Foo = "Hello"; DataContext = o; This doesn't work in Silverlight 5. Is there a way to make it work…
John
  • 6,693
  • 3
  • 51
  • 90
3
votes
2 answers

Dynamic model with Telerik ASP MVC

Has anyone found a way to dynamically create a grid using ExpandoObject, DynamicObject or Reflection.Emit and at the same time allow CRUD operations? I was able to use Reflection.Emit to dynamically create my grid columns and display data, but once…
3
votes
1 answer

Use of expando objects in views?

Edit: Seems numerous people think this is a dumb idea, so I would appreciate an explanation of why it's bad? I was trying to make one partial view that could handle a list of any models to display in table format. I was planning on extending it then…
SventoryMang
  • 10,275
  • 15
  • 70
  • 113
3
votes
0 answers

Deserializing Guids using Json.Net to ExpandoObject loses type and is a string

Given the following class: public class Entity { public Guid UniqueId { get; set; } } The following test fails: [Test] public void GuidTest() { var entity = new Entity { UniqueId = Guid.NewGuid() }; …
David Peden
  • 17,596
  • 6
  • 52
  • 72
3
votes
2 answers

Binding to a ExpandoObject in Blazor

I've build a class which has a dynamic list of properties (such as color, size, weight etc etc), the contents of this aren't known at compile time so I used a ExpandoObject Where I'm struggling is to get Blazor to bind to the value properties of the…
John Mitchell
  • 9,653
  • 9
  • 57
  • 91