C# 4.0
           dynamic
                or:
How I Learned to Stop Worrying and
           Love dynamic
“C# is still a statically typed language everywhere that
you are not using dynamic” – John Skeet

"Oh, well it's statically-typed as a dynamic type.“ – Scott
Hanselman blog

“C# is evolving nicely by introducing dynamic typing
through a static type called dynamic” – Nikhil Kothari
Office Interop
object oDocCustomProps = doc.CustomDocumentProperties;
Type typeDocCustomProps = oDocCustomProps.GetType();
typeDocCustomProps.InvokeMember(
               "Item",
               BindingFlags.Default |
               BindingFlags.SetProperty,
               null, oDocCustomProps,
               new object[] {propertyName, propertyValue});



                                     VS

aDoc.CustomDocumentProperties["CustomProperty1"] = "Alt.NET";
Calling Iron* from C#
ScriptEngine engine = Ruby.CreateEngine();
ScriptScope scope = engine.CreateScope();
engine.ExecuteFile("tax.rb", scope);

var CalculateTax =
         scope.GetVariable<Func<TaxableItem[], decimal>>("calculate_tax");

var items = new TaxableItem[] {
                new TaxableItem("Cola", 2.5),
                new TaxableItem("Donut",1.5)
            };

var tax = CalculateTax(items);

Console.WriteLine("Tax: {0}", tax);

Console.ReadLine();
Calling Iron* from C#
class Item                         def calculate_tax(items)
     def initialize(name, price)        total = 0.0
          @name = name
          @price = price                 items.each do |item|
     end                                      total += item.price * 0.1
                                          end
      def name
          @name                          return total
      end                          end

      def price
            @price
      end
end
C# 4.0 dynamic

C# 4.0 dynamic

  • 1.
    C# 4.0 dynamic or: How I Learned to Stop Worrying and Love dynamic
  • 3.
    “C# is stilla statically typed language everywhere that you are not using dynamic” – John Skeet "Oh, well it's statically-typed as a dynamic type.“ – Scott Hanselman blog “C# is evolving nicely by introducing dynamic typing through a static type called dynamic” – Nikhil Kothari
  • 5.
    Office Interop object oDocCustomProps= doc.CustomDocumentProperties; Type typeDocCustomProps = oDocCustomProps.GetType(); typeDocCustomProps.InvokeMember( "Item", BindingFlags.Default | BindingFlags.SetProperty, null, oDocCustomProps, new object[] {propertyName, propertyValue}); VS aDoc.CustomDocumentProperties["CustomProperty1"] = "Alt.NET";
  • 6.
    Calling Iron* fromC# ScriptEngine engine = Ruby.CreateEngine(); ScriptScope scope = engine.CreateScope(); engine.ExecuteFile("tax.rb", scope); var CalculateTax = scope.GetVariable<Func<TaxableItem[], decimal>>("calculate_tax"); var items = new TaxableItem[] { new TaxableItem("Cola", 2.5), new TaxableItem("Donut",1.5) }; var tax = CalculateTax(items); Console.WriteLine("Tax: {0}", tax); Console.ReadLine();
  • 7.
    Calling Iron* fromC# class Item def calculate_tax(items) def initialize(name, price) total = 0.0 @name = name @price = price items.each do |item| end total += item.price * 0.1 end def name @name return total end end def price @price end end