Serialize the world?

xiaoxiao2021-03-06  49

Just wrote a previous POST, I saw this problem on 9CBS: How to save the interface, such as depositing a database or XML

The first thing I thought is, of course, the serialization mechanism of .NET, but unfortunately open MSDN, find that the subclass of SYSTEM.WINDOWS.FORMS.Control does not have a [Serializable] tag, and the root will not pass.

There is also a way to let your own FORM inherit the iSerializable interface, which controls the serialization. But the problem is that there are too many contents of serialization, and the encoding is reproduced and error-wrong.

Lenovo. NET cool reflex mechanism, and the skill written in POST, my current idea is to use the reflex mechanism to get the object's field (not attribute, attribute or method) and the value of the field, extract one The list, the object within the object is processed by the same method, and such recursive calls can be made to all objects into a collection of primitive types (such as INT type)? Thus, you can easily save files such as XML or in the database?

I think that FCL's built-in binaryformatter and SOAPFormatter work is roughly the same. Only, they ask all types with the [Serializable] tag, otherwise it will pop up an exception. In fact, most of the types that do not have this label are often serialized, but developers are not willing to add.

This cautious approach to the FCL designer allows the FCL's built-in [Serializable] tag, which is completely the same before serialization, while other types are not allowed to be serialized. It specifies the reason, such as the class such as Socket, sequentialization it is often meaningful because it is closely related to its environment. However, most of its attributes still support the inner fields that meet the actual meaning, such as the internal fields corresponding to the three parameters of the constructor, which gives us the possibility of "super serialization tool".

转载请注明原文地址:https://www.9cbs.com/read-83266.html

New Post(0)