English 中文(简体)
NET的航空化
原标题:Serialization in .NET

我的任务是使物体的序列化和脱硫。

I want to know:

  • Whether my object is serialized in the way I m doing it
  • How I get to know that my object is being serialized or deserialized

我不是通过Serialize方法学中的物体,而是通过object.properties。 这是否以任何方式影响到它?

FileStream fs = new FileStream(@"D:Rough WorkSerializationSerializationinDebugLog.txt",FileMode.OpenOrCreate);
Laptop obj = new Laptop();
obj.Model = 2;
obj.SerialNumber = 4;
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, obj.Model);
formatter.Serialize(fs, obj.SerialNumber);

[Serializable]
class Laptop
{
    public int Model;
    public int SerialNumber;
}
问题回答
  • If you can successfully deserialize an object then you serialized it correctly.
  • 你们不需要单独地将财产分类。 你们只能把整个物体编成序号,以同样的方式加以利用。

    using (var fs = new FileStream(@"D:Rough WorkSerializationSerializationinDebugLog.txt",FileMode.OpenOrCreate))
    {
        var formatter = new BinaryFormatter();
        formatter.Serialize(fs, obj);
    }
    
    using (var fs = new FileStream(@"D:Rough WorkSerializationSerializationinDebugLog.txt",FileMode.OpenOrCreate))
    {
        var formatter = new BinaryFormatter();
        obj = formatter.Deserialize(fs) as Laptop;
    }
    

如果你问,拉普特班如何知道它正在编成序号,那么你可能会希望执行

See BinaryFormatter.Deserialize

您可以转换成序列式方法,将其推向碎条窗。

I want to know: Whether my object is serialized in the way I m doing it

Then you can use xml serialization, that way you can check your serialized object since it will be in human-readable form.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签