Ejemplo n.º 1
0
        /// <summary>
        /// Write object/value to XML to string writer.
        /// Project site: http://code.google.com/p/nserializer/
        /// </summary>
        /// <param name="value">
        /// Object instance to write.
        /// </param>
        public void Write(object value, TextWriter writer)
        {
            system.Get<ILogger>().Info("Start write");

            system.Get<IApplicationObjectsRepository>().Initialize();

            var version = value.GetType().Assembly.GetName().Version;

            var typeNameMapper =
                new MigrationDefinitionFactory(version, system.Get<IMigrationRulesBuilder>(), system.Get<ILogger>()).Create().GetTypeNameMapper();

            var typeNamesCache = new TypeNamesCache(typeNameMapper);
            var valueWriterFactory = new DefaultValueWriterFactory(system.Get<IDocumentWriter>(), system.Get<IApplicationObjectsRepository>(),
                                                                   typeNamesCache);
            var objectWriter = valueWriterFactory.Create();

            system.Get<IDocumentWriter>().BeginWrite(writer);

            var payload = new Payload(value);
            objectWriter.Write(payload, system.Get<IDocumentWriter>().RootNode, payload.GetType());

            WriteMetadata(version, typeNamesCache);

            system.Get<IDocumentWriter>().EndWrite();

            system.Get<ILogger>().Debug("Write completed");
        }
Ejemplo n.º 2
0
 private void WriteMetadata(Version targetVersion, ITypeNamesCache typeNamesCache)
 {
     var valueWriterFactory = new DefaultValueWriterFactory(system.Get<IDocumentWriter>(), system.Get<IApplicationObjectsRepository>(), new NullTypeNamesCache());
     var metaDataWriter = valueWriterFactory.Create();
     var metaData = new MetaData(typeNamesCache.Names, targetVersion);
     metaDataWriter.Write(metaData, system.Get<IDocumentWriter>().RootNode, metaData.GetType());
 }