Questions tagged [dynamicobject]

A Microsoft .NET Framework (version 4+) base class for specifying dynamic behavior at run time.

The DynamicObject class enables you to define which operations can be performed on dynamic objects and how to perform those operations. The DynamicObject class enables you to override operations like getting or setting a member, calling a method, or performing any binary, unary, or type conversion operation.

Inheritance Hierarchy

System.Object   
  System.Dynamic.DynamicObject

Reference: https://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject%28v=vs.110%29.aspx

171 questions
198
votes
4 answers

Differences between ExpandoObject, DynamicObject and dynamic

What are the differences between System.Dynamic.ExpandoObject, System.Dynamic.DynamicObject and dynamic? In which situations do you use these types?
M4N
  • 94,805
  • 45
  • 217
  • 260
112
votes
5 answers

dynamic does not contain a definition for a property from a project reference

I am getting an error that says: 'object' does not contain a definition for 'Title' all the code is also on github I have a ConsoleApplication1 that looks like this namespace ConsoleApplication1 { class Program { static void…
eiu165
  • 6,101
  • 10
  • 41
  • 59
61
votes
5 answers

Is there a way to convert a dynamic or anonymous object to a strongly typed, declared object?

If I have a dynamic object, or anonymous object for that matter, whose structure exactly matches that of a strongly typed object, is there a .NET method to build a typed object from the dynamic object? I know I can use a LINQ…
ProfK
  • 49,207
  • 121
  • 399
  • 775
53
votes
1 answer

C# 4.0 Dynamic vs Expando... where do they fit?

I am trying to learn all the new goodies that come with C# 4.0. I am failing to understand the differences between the DynamicObject and ExpandoObject types. It seems like DynamicObject is used e.g. when you want to access variables from Python…
Perpetualcoder
  • 13,501
  • 9
  • 64
  • 99
45
votes
3 answers

Loop DynamicObject properties

I'm trying to understand the DynamicObject type. Found this MSDN article to be very consise and clear as how to create and use DynamicObject: http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject.aspx The article contains a simple…
joeriks
  • 3,382
  • 8
  • 32
  • 42
39
votes
3 answers

Cannot apply indexing with [] to an expression of type 'System.Dynamic.DynamicObject'

When I try to assign a value to the ViewBag I get the following error: Cannot apply indexing with [] to an expression of type 'System.Dynamic.DynamicObject' My code is as follows: public ActionResult Success() { ViewBag["SuccessBody"] =…
RealityDysfunction
  • 2,609
  • 3
  • 26
  • 53
18
votes
3 answers

Get generic type of call to method in dynamic object

I'm starting to work with dynamic objects in .Net and I can't figure out how to do something. I have a class that inherits from DynamicObject, and I override the TryInvokeMember method. e.g. class MyCustomDynamicClass : DynamicObject { public…
willvv
  • 8,439
  • 16
  • 66
  • 101
17
votes
5 answers

Is there mongodb C# driver support System.Dynamic.DynamicObject in .NET 4?

Im working on a project that use .NET Razor and mongodb. I would like to do something like this: @{ var feeds = DP.Database.GetCollection("feeds").FindAll(); }
    @foreach (dynamic feed in feeds) {
  • @feed.message -…
hoang
  • 193
  • 1
  • 2
  • 9
14
votes
3 answers

Is there a way to create a DynamicObject that supports an Interface?

Can I define a class which derives from DynamicObject and supports an interface (ICanDoManyThings) without having to implement each method in the interface? I'm trying to make a dynamic proxy object, and want the method invocations on this class to…
gap
  • 2,766
  • 2
  • 28
  • 37
12
votes
2 answers

Binding DynamicObject to a DataGrid with automatic column generation?

I'm still experimenting with DynamicObjects. Now I need some information: I'm trying to bind an object inheriting from DynamicObject to a WPF DataGrid (not Silverlight). How do I get the DataGrid to automatically create its columns from the…
Hendrik Wiese
  • 2,010
  • 3
  • 22
  • 49
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
1 answer

Determining the expected type of a DynamicObject member access

Is it possible to determine what type a dynamic member access expects? I've tried dynamic foo = new MyDynamicObject(); int x = foo.IntValue; int y = (int)foo.IntValue; And in the TryGetMember intercept GetMemberBinder.ReturnType is object either…
Arne Claassen
  • 14,088
  • 5
  • 67
  • 106
10
votes
2 answers

Convert type 'System.Dynamic.DynamicObject to System.Collections.IEnumerable

I'm successfully using the JavaScriptSerializer in MVC3 to de-serialize a json string in to a dynamic object. What I can't figure out is how to cast it to something I can enumerate over. The foreach line of code below is my latest attemt but it…
user1842828
  • 311
  • 3
  • 9
  • 17
9
votes
1 answer

DynamicObject behaves differently for null values

Here is a DynamicDataObject class derived from DynamicObject public class DynamicDataObject : DynamicObject { private readonly Dictionary _dataDictionary = new Dictionary(); public override bool…
Vimal CK
  • 3,543
  • 1
  • 26
  • 47
9
votes
3 answers

Read values from a Dynamic Object C#

I'm trying to read values from System.Web.Helpers.DynamicJsonObject. I can see the values in the debugger but I can't figure out how to access them. I have tried this item.GetType().GetProperty("batch_id").GetValue(item, null); but when I try that…
MindGame
  • 1,211
  • 6
  • 29
  • 50
1
2 3
11 12