< Day Day Up > |
IntroductionBack in Chapter 1, I illustrated just enough .NET and Managed Extensions basics to get you to the point of being able to mix MFC and BCL code. In the ensuing chapters, I intentionally stayed away from allowing this book to become a "Managed Extensions book" and instead focused on the coverage of various BCL classes and how they could be used in MFC applications. Hopefully, since you've reached this point of the book, you've discovered what led me to pen this text to begin with�namely, that by combining the MFC and BCL class libraries, you end up with the best of both worlds and, as a result, become a more productive software developer. That leads me to the focus of this particular chapter. While the majority of the previous chapters' code snippets and demo applications declared managed objects either as native class members or as local variables, you'll find that the more you mix MFC and managed code, the more you'll have a need to treat your managed objects as you do your native objects. For example, it's common in MFC applications to group semantically related objects in collections or arrays. Typically this is done with either the various map collections or their "templatized" cousins. Unfortunately, you can't store managed objects in the native collections that we're accustomed to using; therefore, one of the tasks that we'll cover here is how to use the various collection types in the BCL to group managed objects. To that end, the chapter begins by introducing the basic interfaces that collection classes implement in order to be called collections. From there, you will see how several of the most commonly used collection classes chose to implement those interfaces in order to give you a wide variety of collection types. The collection classes that you'll learn about are the ArrayList, Hashtable, SortedList, Queue, and Stack classes. Once you've seen the most commonly used collection classes and understand their interface underpinnings, you'll then learn how to design and code a custom collection class that can be treated (from a client code perspective) just as if it were one of the BCL-supplied collection classes. The example illustrated will allow for the enumeration and sorting of a collection of Programmer objects and will be completed with a step-by-step MFC demo application that shows how easy a custom collection can make client-side code that needs to use an enumerable, sortable collection for grouping managed objects. Another basic task that is performed on native objects is that of serialization via the CArchive and related MFC classes. Once again, attempting to serialize managed classes using a native technique is far more trouble than it's worth. However, it's obviously very convenient to be able to persist your objects to and from disk in certain applications. Therefore, the last section of this chapter will introduce you to a very quick and easy technique of serializing entire managed objects to and from disk. After that you'll learn how to use attributes to specify which members of a class to serialize and even discover the technique of custom serialization, which gives you the most control over which members are serialized and how they're serialized. |
< Day Day Up > |
No comments:
Post a Comment