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
3
votes
1 answer

why is ExpandoObject much slower than Dictionary?

I did two tests. 1- how long does it take to add 100k elements. 2- how many searches he can do in 10 seconds using 100k elements. my results were these ExpandoObject Add counter 97075 Dictionary Add counter 35 ExpandoObject Search counter…
cronos
  • 33
  • 5
3
votes
3 answers

Writing a list of complex objects to CSV file using CSVHelper

I have a list of class objects, which in turn contain a list of another class objects. They look like this: public class Column { public string ColName { get; set; } public List ItemList { get; set; } } public class Item { public…
Sach
  • 10,091
  • 8
  • 47
  • 84
3
votes
1 answer

Serilog and ExpandoObject

If I have ExpandoObject like this: dynamic d = new ExpandoObject(); d.x = "a"; d.y = "b"; and log it with Serilog to RollingFile using JsonFormatter like this: _logger.Debug("{@d}", d); it will be serialised to json like…
Andrew
  • 1,139
  • 1
  • 12
  • 27
3
votes
2 answers

Is there a way to perform a chained null check in a dynamic/expando?

C# has the usefull Null Conditional Operator. Well explained in this answer too. I was wondering if it is possible to do a similar check like this when my object is a dynamic/expando object. Let me show you some code: Given this class…
Ewerton
  • 4,046
  • 4
  • 30
  • 56
3
votes
1 answer

Extending the DefaultContractResolver to convert ExpandoObject sub properties to PascalCase

I am trying to write a custom contract resolver that extends DefaultContractResolver in Newtonsoft.Json.Serialization, with the goal of converting all properties within an ExpandoObject to have PascalCase property names. My contract: public class…
Msgm
  • 31
  • 3
3
votes
1 answer

Best way to convert a JArray object to a List of dynamic ExpandoObjects

Our angularjs spa is sending a list of dynamic objects to our backend. I've read that the best way to receive such a list is to use a JArray. Since our business layer is built to receive a list of dynamic objects I need to convert the array. For…
JohanLarsson
  • 475
  • 1
  • 8
  • 23
3
votes
3 answers

Change System.Dynamic.ExpandoObject default behavior

I've a dynamic object created using System.Dynamic.ExpandoObject(), now in some cases some properties could not exists, and if try to access to those in this way myObject.undefinedProperties; the default behavior of the object is to throw the…
davidinho
  • 169
  • 1
  • 14
3
votes
5 answers

C# - Adding objects dynamically (adding dynamic property names)

I'm trying to create some dynamic ExpandoObject. I've encountered a certain problem. As I don't know what the name of these different properties in my objects should be, I can't do like this: var list = new ArrayList(); var obj = new…
Detilium
  • 2,868
  • 9
  • 30
  • 65
3
votes
1 answer

How to get the type as nullable when using Expando object

I am having the collection which is dynamic type. I have stored the double values in the collection. For some records, I am not store the data to it. Now I need to get this type as nullable double to perform some operations. Is there any way to get…
Elavarasan M
  • 182
  • 1
  • 11
3
votes
1 answer

How can I apply an implicit cast on numeric types using Expression Trees?

I have an ExpandoObject with an int field, and I want to cast it to a decimal using an expression tree. Here is the method I'm using : private static Expression> CreateLambdaCastExpression() { // source var…
Brann
  • 31,689
  • 32
  • 113
  • 162
3
votes
1 answer

Iterate through an ExpandoObject that contains multiple ExpandoObjects

I wondered if it is possible to iterate over an ExpandoObject that contains an array of Expando Objects? I am currently parsing some JSON with a file structure like the below: "event": [{ "name": "BEGIN!", "count": 1 }], "context": …
3
votes
2 answers

ExpandoObject to DataTable

I'm new ExpandoObject (indeed, i found out about it yesterday). I have the following code and wonder if there is a method of some sort to convert ExpandoObject to a DataTable that I'm not aware of? Or i have to use reflection to convert it myself?…
NKD
  • 1,039
  • 1
  • 13
  • 24
3
votes
1 answer

ExpandoObject Property not found

Here is a ViewModel property definition. private List productList; public List Products { get { return productList; } set { productList = value; } } On the selectedProduct…
3
votes
1 answer

Web Api - How to return a dynamic object with 201 status code

I'm trying to return the recently added entity Id in a Web Api action method as a JSON. Example: { bookId = 666 } The Controller Action code is as follows: [HttpPost, Route("")] public HttpResponseMessage Add(dynamic inputs) { int bookId =…
Xavier Egea
  • 4,712
  • 3
  • 25
  • 39
3
votes
2 answers

Cannot apply indexing with [] to an expression of type 'object' (even though the type is 'dynamic')

I have an ExpandoObject which is created like so: public ExpandoObject Get() { var expando = new ExpandoObject(); var expandoDic = (IDictionary)expando; // go through the items in the dictionary and copy over the key…
Maloric
  • 5,525
  • 3
  • 31
  • 46