Instantly share code, notes, and snippets.

What would you like to do?
IronPython and C# 4 "dynamic"
using System;
using IronPython.Hosting;
public class dynamic_demo {
static void Main() {
var ipy = Python.CreateRuntime();
dynamic mock = ipy.UseFile("");
// Calls the Python Mock type's constructor
dynamic m = mock.Mock();
//The Python Mock type dynamically implements any member that is requested of it
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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment