Exemplo n.º 1
0
        public T Deserialize <T>(IDataReader reader, object obj)
        {
            object value = null;
            var    type  = typeof(T);

            if (!reader.IsEmptyElement)
            {
                var formatter = FormatterFactory.Get(type);
                int id        = reader.ReadId();
                reader.ReadStartNode(type.Name);
                value = formatter.Read(reader, obj);
                if (id > -1)
                {
                    CycleUtility.GetInstance(reader).AddReference(id, value);
                }
                reader.ReadEndNode(type.Name);
            }
            CycleUtility.RemoveInstance(reader);

            return((T)value);
        }
Exemplo n.º 2
0
        public void Serialize(IDataWriter writer, object obj)
        {
            try
            {
                if (writer == null)
                {
                    throw new ArgumentNullException(nameof(writer));
                }
                if (obj == null)
                {
                    throw new ArgumentNullException(nameof(obj));
                }

                var type      = obj.GetType();
                var formatter = FormatterFactory.Get(type);
                writer.WriteStartNode(type.Name);
                formatter.Write(writer, obj);
                writer.WriteEndNode(type.Name);
                CycleUtility.RemoveInstance(writer);
            }
            catch
            {
            }
        }