Ejemplo n.º 1
0
        public void Serialize(Stream serializationStream, object graph, SerializationSettings settings = null)
        {
            if (_writer == null)
            {
                throw new InvalidOperationException("The value of property 'Writer' is null.");
            }

            if (graph == null)
            {
                return;
            }

            //激发“Serializing”事件
            this.OnSerializing(new SerializationEventArgs(SerializationDirection.Output, serializationStream, graph));

            //创建序列化上下文对象
            var context = new SerializationContext(this, serializationStream, graph, (settings ?? _settings));

            try
            {
                //通知序列化写入器的当前所处步骤(序列化开始)
                _writer.OnSerializing(context);

                //进行序列化写入操作
                this.Write(new SerializationWriterContext(_writer, context, null, graph, null, -1, 0, false, this.IsCollection(graph)), new HashSet <object>());
            }
            finally
            {
                //通知序列化写入器的当前所处步骤(序列化结束)
                _writer.OnSerialized(context);
            }

            //激发“Serialized”事件
            this.OnSerialized(new SerializationEventArgs(SerializationDirection.Output, serializationStream, graph));
        }
Ejemplo n.º 2
0
        public Serializer(ISerializationWriter writer, SerializationSettings settings)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            _writer   = writer;
            _settings = settings ?? new SerializationSettings();
        }
		public SerializationContext(ISerializer serializer, Stream serializationStream, object serializationObject, SerializationSettings settings)
		{
			if(serializer == null)
				throw new ArgumentNullException("serializer");

			if(serializationObject == null)
				throw new ArgumentNullException("serializationObject");

			if(serializationStream == null)
				throw new ArgumentNullException("serializationStream");

			_settings = settings;
			_serializer = serializer;
			_serializationStream = serializationStream;
			_serializationObject = serializationObject;
		}
Ejemplo n.º 4
0
        public SerializationContext(ISerializer serializer, Stream serializationStream, object serializationObject, SerializationSettings settings)
        {
            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            if (serializationObject == null)
            {
                throw new ArgumentNullException("serializationObject");
            }

            if (serializationStream == null)
            {
                throw new ArgumentNullException("serializationStream");
            }

            _settings            = settings;
            _serializer          = serializer;
            _serializationStream = serializationStream;
            _serializationObject = serializationObject;
        }
        private Newtonsoft.Json.JsonSerializer GetSerializer(Zongsoft.Runtime.Serialization.SerializationSettings settings)
        {
            var serializer = Newtonsoft.Json.JsonSerializer.Create(this.GetSerializerSettings(settings as TextSerializationSettings ?? _settings));

            return(serializer);
        }