I believe you are interested in the ExpandoObject class. The DynamicObject class is just a base where you have to provide all the logic. It explicitly implements the IDictionary<string, object> interface so that you can access its properties or add new ones in this way.
// declare the ExpandoObject dynamic expObj = new ExpandoObject(); expObj.Name = "MyName"; expObj.Number = 1000; // print the dynamically added properties foreach (KeyValuePair<string, object> kvp in expObj) // enumerating over it exposes the Properties and Values as a KeyValuePair Console.WriteLine("{0} = {1}", kvp.Key, kvp.Value); // cast to an IDictionary<string, object> IDictionary<string, object> expDict = expObj; // add a new property via the dictionary reference expDict["Foo"] = "Bar"; // verify it been added on the original dynamic reference Console.WriteLine(expObj.Foo);
I just realized that you are implementing the DynamicDictionary class and misunderstanding your question. Unfortunately.
When used with a dynamic link, you only have access to open members. Since only Count declared publicly available (among other DynamicObject members), you will need to use reflection to access the internal dictionary, to easily get these values (unless you intend to make any further changes).
Jeff Mercado Jan 27 '11 at 9:25 a.m. 2011-01-27 09:25
source share