<mock.py>
import random math
class Mock (object):
def __getattr __ (self, key):
"" "Dynamically implement"
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
System.Console.WriteLine (m.the_csharp_compiler_cannot_possbily_know_this_member_exists_at_compile_time);
}
}
<dynamic_demo.cs>
Source: https://habr.com/ru/post/60079/
All Articles