Running with Code Like with scissors, only more dangerous

10Aug/100

C# 4.0 and Dynamic Programming @ AZDNUG

Posted by Rob Paveza

I’m officially posting my code samples and slides BEFORE the presentation tonight so that I can actually claim that they’re online.  They are downloadable at http://robpaveza.net/pub/dynamics-presentation.zip – includes the project folder, the “building-up-the-code” part (including the IronPython code), and the slides.

The project requires Visual C# 2010 to open.  Executing the Python code will require IronPython 2.6 for .NET 4.0 (available here).  You may need to modify the paths in the Python code to make it work exactly right as it relies on some paths, and in fact, the Python code won’t run until you’ve build an executable for the Cs4Dynamics project.

6Aug/100

Cool Dynamic Code and Talking at AZDNUG on August 10

Posted by Rob Paveza

I’ll be giving a talk next Tuesday, August 10 at the AZ .NET User Group where I’ll be giving a brief treatment on C# 4.0’s new features and primarily be talking about the cool stuff you can do with dynamic code in C#. 

To whet your appetite, here’s some of the code we’ll be reviewing next week:

        static void Main(string[] args)
        {
            string xmlPath = Path.Combine(Environment.CurrentDirectory, "SampleBooks.xml");
            dynamic xml = new DynamicXml(xmlPath);

            foreach (dynamic child in xml)
            {
                string id = child.id;
                Console.WriteLine("BOOK ID: {0}", id);
                Console.WriteLine(child);
            }

            xml.books.SetDefaultIdentifier("id");
            dynamic vs7 = xml.books["bk112"];
            Console.WriteLine("VS7 Book:");
            Console.WriteLine(vs7);

            Console.WriteLine("Title: {0}", xml.books["bk107"].title);

            xml.books["bk113"] = new { Title = "This is a test", 
                  Description = "This is me adding a new anonymous object " +
                  "to the property of a dynamic object by calling SetIndex.", 
                  Author = "Rob Paveza" };
            xml.SaveAs(Path.Combine(Environment.CurrentDirectory, 
                  "SampleBooks-Output.xml"));

            xml.books["bk113"] = new { Title = "This is a replacement", 
                  Description = "This is me replacing an existing dynamic " +
                  "object's property with a new one by calling SetIndex.", 
                  Author = "Rob Paveza" };
            xml.SaveAs(Path.Combine(Environment.CurrentDirectory, 
                  "SampleBooks-Output2.xml"));

            Console.ReadLine();
        }

The user group is meeting at the Microsoft district office at 2929 N. Central Ave., Phoenix (just north of Thomas on Central).  It’ll be on the 14th floor.  I believe pizza will be served.  More info at AZGroups.org

I hope to see you there!

Filed under: Uncategorized No Comments