Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/01/11 12:40:12 (14 years ago)
Author:
epitzer
Message:

Support exporting types in type cache and add a support method for XmlGenerator to access this list (#1403)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs

    r4068 r5403  
    405405    public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies) {
    406406      try {
    407         using (StreamWriter writer = new StreamWriter(new GZipStream(stream, CompressionMode.Compress))) {
    408           Serializer serializer = new Serializer(obj, config);
    409           serializer.InterleaveTypeInformation = true;
    410           XmlGenerator generator = new XmlGenerator();
    411           foreach (ISerializationToken token in serializer) {
    412             string line = generator.Format(token);
    413             writer.Write(line);
    414           }
    415           writer.Flush();
     407        Serializer serializer = new Serializer(obj, config);
     408        Serialize(stream, serializer);
     409      } catch (PersistenceException) {
     410        throw;
     411      } catch (Exception e) {
     412        throw new PersistenceException("Unexpected exception during Serialization.", e);
     413      }
     414    }
     415
     416    /// <summary>
     417    /// Serializes the specified object into a stream.
     418    /// </summary>
     419    /// <param name="obj">The object.</param>
     420    /// <param name="stream">The stream.</param>
     421    /// <param name="config">The configuration.</param>
     422    /// <param name="includeAssemblies">if set to <c>true</c> include need assemblies.</param>
     423    /// <param name="types">The list of all serialized types.</param>
     424    public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies, out IEnumerable<Type> types) {
     425      try {
     426        Serializer serializer = new Serializer(obj, config);
     427        Serialize(stream, serializer);
     428        types = serializer.SerializedTypes;
     429      } catch (PersistenceException) {
     430        throw;
     431      } catch (Exception e) {
     432        throw new PersistenceException("Unexpected exception during Serialization.", e);
     433      }
     434    }
     435
     436    private static void Serialize(Stream stream, Serializer serializer) {
     437      using (StreamWriter writer = new StreamWriter(new GZipStream(stream, CompressionMode.Compress))) {
     438        serializer.InterleaveTypeInformation = true;
     439        XmlGenerator generator = new XmlGenerator();
     440        foreach (ISerializationToken token in serializer) {
     441          string line = generator.Format(token);
     442          writer.Write(line);
    416443        }
    417       }
    418       catch (PersistenceException) {
    419         throw;
    420       }
    421       catch (Exception e) {
    422         throw new PersistenceException("Unexpected exception during Serialization.", e);
     444        writer.Flush();
    423445      }
    424446    }
Note: See TracChangeset for help on using the changeset viewer.