Pull to refresh

Вышел IronPython 2.6 CTP для .NET 4.0 Beta 1

Reading time1 min
Views598
Главная новость релиза — интеграция с динамическими объектами .NET 4



Пример:

 <mock.py>
        import random, math
        
        class Mock(object): 
            def __getattr__(self, key):
                """Mock objects of this type will dynamically implement any requested member"""
                return random.choice(["hello world", math.pi])
     </mock.py>
 
    <dynamic_demo.cs>
        using System;
        using IronPython.Hosting;
        using Microsoft.Scripting.Hosting;
        
        public class dynamic_demo {
            static void Main() {      
               var ipy = Python.CreateRuntime();
               dynamic mock = ipy.UseFile("mock.py");
               dynamic m = mock.Mock();
               //The Python Mock type dynamically implements any member that is requested of it
               System.Console.WriteLine(m.the_csharp_compiler_cannot_possbily_know_this_member_exists_at_compile_time);
            }
        }
    <dynamic_demo.cs>
Tags:
Hubs:
+3
Comments1

Articles