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
24
votes
3 answers

Using LINQ, is it possible to output a dynamic object from a Select statement? If so, how?

Presently in LINQ, the following compiles and works just fine: var listOfFoo = myData.Select(x => new FooModel{ someProperty = x.prop1, someOtherProperty = x.prop2 }); public class FooModel{ public string someProperty { get; set;…
Matt Cashatt
  • 23,490
  • 28
  • 78
  • 111
22
votes
2 answers

'System.Collections.Generic.IList' does not contain a definition for 'Add' when using 'dynamic' and 'ExpandoObject'
Say that I have a class, Foo, looking something like this: public class Foo : IFoo { public Foo() { Bars = new List(); } public IList Bars { get; set; } } The interface IFoo looks like: public interface…
Kodo
  • 541
  • 1
  • 6
  • 17
20
votes
2 answers

Convert from JSON object to expando object in c#

I have a JSON object, something like: var jsonObject = {"att1" : "val1","att2" : "val2","att3" : "val3","att4" : "val4"} I need to convert the same into an ExpandoObject. I tried something like: var expConverter = new…
satish kumar V
  • 1,695
  • 6
  • 33
  • 47
18
votes
7 answers

Binding a GridView to a Dynamic or ExpandoObject object

I'm using Rob Conery's Massive ORM, and I haven't been able to bind the resulting ExpandoObject to a GridView. I did find another Stackoverflow question that suggests using a framework called impromptu, but I'm not sure if that would work for this.…
GR7
  • 5,083
  • 8
  • 48
  • 66
17
votes
6 answers

How can I use collection initializer syntax with ExpandoObject?

I've noticed that the new ExpandoObject implements IDictionary which has the requisite IEnumerable> and Add(string, object) methods and so it should be possible to use the collection initialiser syntax to…
16
votes
3 answers

.NET 4.0 framework dynamic features in VB with Option Strict On?

Is there any way to use the new dynamic features in the 4.0 framework like ExpandoObject in VB.NET without setting Option Strict Off? With C#, you lose type safety only with the variables you specifically declare as dynamic. But with VB, the only…
mattmc3
  • 17,595
  • 7
  • 83
  • 103
15
votes
1 answer

Deserialize a property as an ExpandoObject using JSON.NET

For example, there's an object like the next one: public class Container { public object Data { get; set; } } And it's used this way: Container container = new Container { Data = new Dictionary { { "Text", "Hello world" }…
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
14
votes
3 answers

how get value on expando object #

First I read txt files into a folder, and after I hydrated objects with expando Object. But now I would like to get some value from this objects to fill a listview (winforms). private void Form1_Load(object sender, EventArgs e) { …
Bissap
  • 521
  • 1
  • 5
  • 23
13
votes
2 answers

can one convert a dynamic object to an ExpandoObject (c#)

I am getting an dynamic object of type "Sealed Class" from a driver api (in dll). I want to decorate this object with a few additional properties. I would like to do something to the effect of: public void expandIT(dynamic sealedObject) { …
Dr.YSG
  • 7,171
  • 22
  • 81
  • 139
13
votes
1 answer

Does C# 4.0's ExpandoObject support Prototype-based inheritance?

Does C# 4.0's ExpandoObject support Prototype-based inheritance? If not, why not (was it by design?) and how could this be implemented? If yes, how does it work and what differences are there compared to the way it works in Javascript?
luvieere
  • 37,065
  • 18
  • 127
  • 179
13
votes
3 answers

Cast ExpandoObject to anonymous type

Can I cast ExpandoObject to anonymous type ? var anoObj = new { name = "testName", email = "testEmail" }; dynamic expandoObj = new System.Dynamic.ExpandoObject(); // Here I'm populating the expandoObj with same property names/types in…
Sency
  • 2,818
  • 8
  • 42
  • 59
12
votes
2 answers

Generate JSON string from dynamic ExpandoObject

I am using C# and trying to generate a JSON string from a dynamic object. dynamic reply = new System.Dynamic.ExpandoObject(); reply.name = "John"; reply.wins = 42; string json =…
Wyck
  • 10,311
  • 6
  • 39
  • 60
12
votes
1 answer

Is it possible to add attributes to a property of dynamic object runtime?

I want to add an attribute to property of a dynamic object/expando object runtime, is it possible? What I would like to do is: dynamic myExpando = new ExpandoObject(); myExpando.SomeProp = "string"; myExpando.AddAttribute("SomeProp", new…
Tomas Jansson
  • 22,767
  • 13
  • 83
  • 137
12
votes
0 answers

Dynamically removing a member from Expando /dynamic object

I'm looking for a way to remove members dynamically from an dynamic object (may be can we use Expando object here?). OK, I guess a little clarification is needed... When you do that : dynamic foo = new ExpandoObject(); foo.Bar = 42; foo.Jar =…
Dhanapal
  • 14,239
  • 35
  • 115
  • 142
11
votes
3 answers

Dynamically adding properties to a dynamic object?

i have this dynamic d = new ExpandoObject(); d.Name = attribute.QualifiedName.Name; so , i know that d will have a property Name. Now if i don't know the name of the property at compile time , how do i add that property to the dynamic. i found…
ashutosh raina
  • 9,228
  • 12
  • 44
  • 80
1
2
3
23 24