简体   繁体   English

如何更改和/或移动已序列化的类?

[英]How do I change and/or move a class that has been serialized?

I've got a class in my project and I want to move and rename that class to somewhere else in the project's namespace. 我的项目中有一个类,我想移动该类并将其重命名为项目名称空间中的其他位置。 I tried simply moving it, but then the program won't deserialize any settings saved under Properties.Settings.Default for that setting. 我尝试简单地移动它,但是程序不会反序列化该设置保存在Properties.Settings.Default下的任何设置。 Is there a way I can move it without losing all of the user's settings? 有什么方法可以移动它而不会丢失所有用户设置?

I think the SerializationBinder contains a solution for your problem. 我认为SerializationBinder包含针对您的问题的解决方案。

From the MSDN documentation: 从MSDN文档中:

Some users need to control which class to load, either because the class has moved between assemblies or a different version of the class is required on the server and client. 一些用户需要控制加载哪个类,因为该类已在程序集之间移动,或者在服务器和客户端上需要该类的不同版本。

I'll assume your using Studio, have you tried dragging the class into a Class Diagram and renaming from there? 我假设您使用Studio,是否尝试过将类拖到“类图”中并从那里重命名? I find that Studio refactors accordingly from the Class Diagram. 我发现Studio从类图中进行了相应的重构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何判断 class 是否可以序列化? - How do I tell if a class can be serialized? 如何指示自定义JSON.NET JsonConverter识别特定属性已在上游进行序列化? - How do I instruct a custom JSON.NET JsonConverter to recognize that a particular property has already been serialized upstream? 按下触发器后,如何更改整个对象的颜色? - How do I change the colour of the whole object once its trigger has been hit? 在序列化之前,如何检查类文件是否已更改? - How do I check if a class file has been changed before serializing it? 当父视图具有相同模型时,如何将局部视图中的 HTML 表单数据序列化? - How do I get HTML form data in Partial View to be serialized when parent view has same model? 如何获取已传递给方法的类 - how can I get which class has been passed to method SerializationException:值已被序列化 - SerializationException: Value has been serialized already 如何在序列化类时更改属性,类层次结构 - How to change attributes, class hierarchy when a class is serialized 处置后如何创建对象? - How do I create an object after it has been disposed? 加载后如何更新DataGrid? - How do I update a DataGrid after it has already been loaded?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM