The document discusses the Dynamic Language Runtime (DLR). The DLR was created by Jim Hugunin to enable dynamic languages like IronPython to run on the .NET Common Language Runtime (CLR). It provides features needed for dynamic languages like a script engine, dynamic typing, metaprogramming, and interoperability between dynamic languages. The DLR also includes expression trees that allow expressions to be compiled at runtime and late binding.
3. DLR是
• Dynamic Language Runtime
• 由 IronPython 发起人Jim Hugunin开发
• 一个构建在CLR之上的运行时
• 在.Net上构建动态语言的标准体系
The DLR's mission is to enable an ecosystem of
dynamic languages on .NET.
22. Method Missing
public class AnyDynamicObject : DynamicObject
{
public override bool TryGetMember(GetMemberBinder binder, out object
result)
{
Console.WriteLine("Shit happens,{0}属性被调用了", binder.Name);
result = "no value";
return true;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
Console.WriteLine("Shit happens,{0}属性被赋值了", binder.Name);
return true;
}
}
23. Method Missing
dynamic any = new AnyDynamicObject();
Console.WriteLine(any.name);
any.age = 100;
Shit happens,name属性被调用了
no value
Shit happens,age属性被赋值了
24. 调用Python引擎
example.py :
引用:
def addPrice(x, y): IronPython.dll
return x + y IronPython.Modules.dll
Microsoft.Dynamic.dll
class User(object):
Microsoft.Scripting.dll
def __init__(self, name, email):
self.Name = name
self.AEmail = email
def say(self):
print "hello"
bob = User("bob", "x@gmail.com")