The Labs \ Source Viewer \ SSCLI \ System.ComponentModel.Design.Serialization \ ComponentSerializationService

  1. //------------------------------------------------------------------------------
  2. // <copyright file="ComponentSerializationService.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.ComponentModel.Design.Serialization
  16. {
  17.    
  18.     using System.Collections;
  19.     using System.ComponentModel;
  20.     using System.IO;
  21.     using System.Security.Permissions;
  22.    
  23.     /// <devdoc>
  24.     /// This class serializes a set of components or serializable objects into a
  25.     /// serialization store. The store can then be deserialized at a later
  26.     /// date. ComponentSerializationService differs from other serialization
  27.     /// schemes in that the serialization format is opaque, and it allows for
  28.     /// partial serialization of objects. For example, you can choose to
  29.     /// serialize only selected properties for an object.
  30.     ///
  31.     /// This class is abstract. Typically a DesignerLoader will provide a
  32.     /// concrete implementation of this class and add it as a service to
  33.     /// its DesignSurface. This allows objects to be serialized in the
  34.     /// format best suited for them.
  35.     /// </devdoc>
  36.     [HostProtection(SharedState = true)]
  37.     public abstract class ComponentSerializationService
  38.     {
  39.        
  40.         /// <devdoc>
  41.         /// This method creates a new SerializationStore. The serialization store can
  42.         /// be passed to any of the various Serialize methods to build up serialization
  43.         /// state for a group of objects.
  44.         /// </devdoc>
  45.         public abstract SerializationStore CreateStore();
  46.        
  47.         /// <devdoc>
  48.         /// This method loads a SerializationStore and from the given
  49.         /// stream. This store can then be used to deserialize objects by passing it to
  50.         /// the various Deserialize methods.
  51.         /// </devdoc>
  52.         public abstract SerializationStore LoadStore(Stream stream);
  53.        
  54.         /// <devdoc>
  55.         /// This method serializes the given object to the store. The store
  56.         /// can be used to serialize more than one object by calling this method
  57.         /// more than once.
  58.         /// </devdoc>
  59.         public abstract void Serialize(SerializationStore store, object value);
  60.        
  61.         /// <devdoc>
  62.         /// Normal serialization only serializes values that differ from the component's default state.
  63.         /// This provides the most compact serialization mechanism but assumes that during deserilalization
  64.         /// a new, freshly created object will be used. If an existing object is used properties that
  65.         /// contained default values during serialization would not be reset back to their defaults.
  66.         /// The SerializeAbsolute method does not require this assumption on the deserializing end.
  67.         /// Instead, it saves data in the serialization store about default values as well so that
  68.         /// deserialization can reset non-default properties back to their default values. This is
  69.         /// especially true for collection objects, where the collections are either cleared and
  70.         /// items re-added, or individual items are removed and added.
  71.         /// </devdoc>
  72.         public abstract void SerializeAbsolute(SerializationStore store, object value);
  73.        
  74.         /// <devdoc>
  75.         /// This method serializes the given member on the given object. This method
  76.         /// can be invoked multiple times for the same object to build up a list of
  77.         /// serialized members within the serialization store. The member generally
  78.         /// has to be a property or an event.
  79.         /// </devdoc>
  80.         public abstract void SerializeMember(SerializationStore store, object owningObject, MemberDescriptor member);
  81.        
  82.         /// <devdoc>
  83.         /// This method serializes the given member on the given object,
  84.         /// but also serializes the member if it contains the default value.
  85.         /// Note that for some members, containing the default value and setting
  86.         /// the same value back to the member are different concepts. For example,
  87.         /// if a property inherits its value from a parent object if no local value
  88.         /// is set, setting the value back to the property can may not be what is desired.
  89.         /// SerializeMemberAbsolute takes this into account and would clear the state of
  90.         /// the property in this case.
  91.         /// </devdoc>
  92.         public abstract void SerializeMemberAbsolute(SerializationStore store, object owningObject, MemberDescriptor member);
  93.        
  94.         /// <devdoc>
  95.         /// This method deserializes the given store to produce a collection of
  96.         /// objects contained within it. If a container is provided, objects
  97.         /// that are created that implement IComponent will be added to the container.
  98.         /// </devdoc>
  99.         public abstract ICollection Deserialize(SerializationStore store);
  100.        
  101.         /// <devdoc>
  102.         /// This method deserializes the given store to produce a collection of
  103.         /// objects contained within it. If a container is provided, objects
  104.         /// that are created that implement IComponent will be added to the container.
  105.         /// </devdoc>
  106.         public abstract ICollection Deserialize(SerializationStore store, IContainer container);
  107.        
  108.         /// <devdoc>
  109.         /// This method deserializes the given store, but rather than produce
  110.         /// new objects, the data in the store is applied to an existing
  111.         /// set of objects that are taken from the provided container. This
  112.         /// allows the caller to pre-create an object however it sees fit. If
  113.         /// an object has deserialization state and the object is not named in
  114.         /// the set of existing objects, a new object will be created. If that
  115.         /// object also implements IComponent, it will be added to the given
  116.         /// container. Objects in the container must have names that
  117.         /// match objects in the serialization store in order for an existing
  118.         /// object to be used. If validateRecycledTypes is true it is guaranteed
  119.         /// that the deserialization will only work if applied to an object of the
  120.         /// same type.
  121.         /// </devdoc>
  122.         public abstract void DeserializeTo(SerializationStore store, IContainer container, bool validateRecycledTypes, bool applyDefaults);
  123.        
  124.         public void DeserializeTo(SerializationStore store, IContainer container)
  125.         {
  126.             DeserializeTo(store, container, true, true);
  127.         }
  128.        
  129.         public void DeserializeTo(SerializationStore store, IContainer container, bool validateRecycledTypes)
  130.         {
  131.             DeserializeTo(store, container, validateRecycledTypes, true);
  132.         }
  133.     }
  134. }

Developer Fusion