5 c# python serialization ironpython pickle
这可能是一个奇怪的问题,但有没有可靠的方法来序列化类扩展CLR类型的IronPython对象?
例如:
class Foo(System.Collections.Generic.List[str]):
def Test(self):
print "test!"
Run Code Online (Sandbox Code Playgroud)
System.Collections.Generic.List<string>可以使用Pickle进行序列化,因为它实现了ISerializable接口,但是可序列化CLR类型的发出子类似乎不起作用,而且我ImportError: No module named Generic in mscorlib, Version=4在运行时得到pickle.dumps(Foo()).
此外,运行通常Formatter.Serialize(stream, object)给我:
SystemError: Type 'IronPython.NewTypes.System.Collections.Generic.List`1_4$4' in Assembly Snippets.scripting, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
Run Code Online (Sandbox Code Playgroud)
在嵌入式C#环境中运行时,如何实现IronPython对象的序列化?
引用自clrtype元类
\n\n\n\n\n今天,IronPython 不支持基于反射的 API 或自定义属性,因为 IronPython 不为每个 Python 类发出自定义 CLR 类型。相反,它通常在许多 Python 类之间共享一个 CLR 类型。例如,所有这三个 Python 类共享一个基础 CLR 类型。
\n
class shop(object):\n pass \n\nclass cheese_shop(shop):\n def have_cheese(self, cheese_type):\n return False\n\nclass argument_clinic(object):\n def is_right_room(self, room=12):\n return "I\'ve told you once"\n\nimport clr\nprint clr.GetClrType(shop).FullName\nprint clr.GetClrType(cheese_shop).FullName\nprint clr.GetClrType(argument_clinic).FullName \nRun Code Online (Sandbox Code Playgroud)\n\n\n\n\n即使cheese_shop继承自shop,而argument_clinic继承自object,所有三个类都共享相同的基础 CLR 类型
\n
我没有尝试过,但也许你可以通过序列化代理手动序列化来解决这个问题手动序列化来解决这个问题。
\n| 归档时间: |
|
| 查看次数: |
1422 次 |
| 最近记录: |