Đang chuẩn bị liên kết để tải về tài liệu:
Effective C#50 Specific Ways to Improve Your C# 2nd phần 6

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Ngôn ngữ trở nên nước ngoài ít hơn, và người bắt đầu nói hiệu quả hơn và rõ ràng hơn. Ngôn ngữ lập trình không khác nhau. Các kỹ thuật mà bạn chọn truyền đạt ý định thiết kế của bạn cho các nhà phát triển những người duy trì, gia hạn, hoặc sử dụng các phần mềm bạn phát triển. C # loại sống trong môi trường NET. | 158 I Chapter 3 Expressing Designs in C serialization properly you create more work for all developers who intend to use your types as a member or base class. When your type does not support serialization they must work around it adding their own implementation of a standard feature. It s unlikely that clients could properly implement serialization for your types without access to private details in your types. If you don t supply serialization it s difficult or impossible for users of your class to add it. Instead prefer adding serialization to your types when practical. It should be practical for all types that do not represent UI widgets windows or forms. The extra perceived work is no excuse. .NET serialization support is so simple that you don t have any reasonable excuse not to support it. In many cases adding the Serializable attribute is enough Serializable public class MyType private string label private int value Adding the Serializable attribute works because all the members of this type are serializable string and int both support .NET serialization. The reason it s important for you to support serialization wherever possible becomes obvious when you add another field of a custom type Serializable public class MyType private string label private int value private OtherClass otherThing The Serializable attribute works here only if the OtherClass type supports .NET serialization. If OtherClass is not serializable you get a runtime error and you have to write your own code to serialize MyType and the OtherClass object inside it. That s just not possible without extensive knowledge of the internals defined in OtherClass. .NET serialization saves all member variables in your object to the output stream. In addition the .NET serialization code supports arbitrary object From the Library of Wow eBook Item 27 Prefer Making Your Types Serializable I 159 graphs Even if you have circular references in your objects the serialize and deserialize methods will save and

TÀI LIỆU LIÊN QUAN