3ewsd 发表于 2017-5-4 09:12:10

IronPython之在C#中获取Python对象的类名

  假设在C#中有一个IronPython的对象 ‘obj1’。
  现在要得到该对象的类名,不是在C#中的类名,而是它在IronPython中的类名。
  (如果要得到在C#中的类名,直接调用对象的GetType()方法,就能获得对应的Type)

dynamic obj1;
Microsoft.Scripting.Hosting.ScriptEngine engine = IronPython.Hosting.Python.CreateEngine();
Microsoft.Scripting.Hosting.ObjectOperations operations = engine.Operations;
string typeName = operations.GetMember(obj1, "__class__").__name__;
页: [1]
查看完整版本: IronPython之在C#中获取Python对象的类名