[dba-VB] What's new in VS2010...

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Mon Sep 27 03:57:13 CDT 2010


Hi All --

I'm reading through here "What's new in VS2010" - one of the most advanced
new features - ExpandoObject:

"The ExpandoObject  class enables you to add and delete members of its
instances at run time and also to set and get values of these members. This
class supports dynamic binding, which enables you to use standard syntax
like sampleObject.sampleMember instead of more complex syntax like
sampleObject.GetAttribute("sampleMember").

The ExpandoObject class implements the standard Dynamic Language Runtime
(DLR) interface IDynamicMetaObjectProvider, which enables you to share
instances of the ExpandoObject class between languages that support the DLR
interoperability model. For example, you can create an instance of the
ExpandoObject class in C# and then pass it to an IronPython function."

-- Shamil

P.S. Code sample:

using System.Dynamic;

...

class Test1
{
    public static void Run()
    {
        dynamic d = new ExpandoObject();
        d.FirstName = "C";
        d.LastName = "Sharp";
        d.City = "Redmond";
        System.Console.WriteLine("{0} {1} {2}", d.FirstName, d.LastName,
d.City);  

        ((IDictionary<String, Object>)d).Remove("City");

        try
        {
            System.Console.WriteLine("{0} {1} {2}", d.FirstName, d.LastName,
d.City);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Error: {0}", ex.Message);  
        }

        System.Console.WriteLine("{0} {1}", d.FirstName, d.LastName);

        //C Sharp Redmond
        //Error: 'System.Dynamic.ExpandoObject' does not contain a
definition for 'City'
        //C Sharp
    }
}




More information about the dba-VB mailing list