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

How do I make WebMethods serialize ExpandoObject

I have a WebMethod that looks like this which is used to populate a jqGrid [System.Web.Script.Services.ScriptService] public class MyWebService: System.Web.Services.WebService { [WebMethod] [Authorize(Roles = "Admin")] public object…
Sean Tomlins
  • 365
  • 3
  • 13
5
votes
3 answers

A List inside an ExpandoObject

dynamic model = new ExpandoObject(); model.Data = "asdf"; List listOfx = new List(); for (int i = 0; i < 3; i++) { dynamic x = new ExpandoObject(); x.ID = i; x.Name = "test" + i.ToString(); …
Dave Mateer
  • 6,588
  • 15
  • 76
  • 125
5
votes
1 answer

Does databinding to dynamics and ExpandoObjects work in .NET

For the life of me I I don't seem to be able to get Databinding to Dynamics or ExpandoObjects working. I have tried this in WinForms and in WebForms and get different results in each: In ASP.NET:
ProVega
  • 51
  • 2
5
votes
4 answers

ExpandoObject, anonymous types and Razor

I want to use an ExpandoObject as the viewmodel for a Razor view of type ViewPage. I get an error when I do this ExpandoObject o = new ExpandoObject(); o.stuff = new { Foo = "bar" }; return View(o); what can I do to make this work?
kenwarner
  • 28,650
  • 28
  • 130
  • 173
5
votes
1 answer

Is it possible to add attributes to the generated members of an ExpandoObject instance?

I'm trying to use an ExpandoObject as the SelectedObject of a PropertyGrid. I know how to add the properties I want to the ExpandoObject: public dynamic MakePropertyObject() { dynamic expando = new ExpandoObject(); var dictionary = expando…
5
votes
1 answer

How to get deserialized xml attribute from dynamic object

I can get the element innertext from expandoobject without any problem. I can't figure out how to get the attribute's value. By doing Console.WriteLine(obj.Message.Body), I can get the expected string inside the body element. private void…
5
votes
2 answers

adding expando properties to a typed object at runtime in c#

Is there any way in .net to bind a dictionary of properties to an instance at runtime, i.e., as if the base object class had a property like: public IDictionary Items { get; } I have come up with a solution involving a static dictionary and…
mcintyre321
  • 12,996
  • 8
  • 66
  • 103
5
votes
3 answers

Short way to achieve dynamic objects from LINQ to XML select query?

Is there an initialization syntax to the ExpandoObject that I can use to my advantage in a LINQ to XML query for brevity purposes? Note: The results of the query are intended to be passed outside the scope of the current assembly so anonymous…
John K
  • 28,441
  • 31
  • 139
  • 229
5
votes
3 answers

Persisting an ExpandoObject to MongoDB

I have an ExpandoObject with an arbitrary number of properties. I want to persist those properties to a MongoDB database as a BsonDocument. I try to do so with the following code: private BsonDocument GetPlayerDocument(IPlayer player) { var ret…
Yes - that Jake.
  • 16,725
  • 14
  • 70
  • 96
5
votes
0 answers

Does ExpandoObject in c# has instance accessor like this?

consider I have this simple c# code: dynamic obj = new ExpandoObject(); obj.FirstName = "John"; obj.LastName = "Doe"; I want to add method which will return full name, John Doe in this case. I know the following line will work, but not sure if it…
Arkadi
  • 1,153
  • 1
  • 14
  • 35
5
votes
1 answer

Using a reserved word (Type name) as ExpandoObject or Dynamic property

How can I possibly set a property of an ExpandoObject with a key that is a reserved word? Like this: dynamic query = new ExpandoObject(); query.size = 10; query.date = "2017-04-27"; dynamic match = new { query = query, bool = true }
Sulaiman Adeeyo
  • 485
  • 6
  • 19
5
votes
1 answer

Can an ExpandoObject be a list?

I am using Json.Net to deserialize json results into ExpandoObjects using code like the following: var converter = new ExpandoObjectConverter(); dynamic d = JsonConvert.DeserializeObject(json, converter); This works great…
dkackman
  • 15,179
  • 13
  • 69
  • 123
5
votes
2 answers

Special characters for dynamic objects?

Is there any limitations on the kind of characters that I can use to create a property for a dynamic object? Is there a list of characters that I cannot use (e.g. / * @)?
Oliver
  • 807
  • 2
  • 12
  • 23
5
votes
4 answers

UI does not update with list of ExpandoObject

I have implemented the dynamic dataGrid by following this link. I am using Converter to bind the values from ExpandoObject. The columns shows values like total units for schools. Item ItemCount DefaultSchool School1 School2 School3 X-Item …
Learner
  • 1,490
  • 2
  • 22
  • 35
5
votes
1 answer

Using C# ExpandoObjects (Dynamic) in PowerShell without underlying Dictionary structure

I have an ExpandoObject in C# that has been initialized with a great deal of fields/properties and I want to use this object in a PowerShell environment. When I retrieve such an object in PowerShell it doesn't display all the fields/properties as…
Joey Dewd
  • 1,804
  • 3
  • 20
  • 43