Exemplo n.º 1
0
        /// <summary>
        /// Converts an object into XML.
        /// </summary>
        /// <param name="value">The object to serialize.</param>
        /// <returns>A string containing the serialization of the given object.</returns>
        public string Serialize(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            lock (_lockObject)
            {
                // Don't allow reentrance
                _visitedObjects = new ObjectXmlReferences();
                _typeCache      = new Dictionary <Type, int>();

                var document = new XDocument(WriteValue(XmlConstants.ROOT, null, value));
                if (document.Root != null)
                {
                    document.Root.AddFirst(WriteTypeCache());
                }
                string result = ConvertDocumentToString(document);

                CleanUp();

                return(result);
            }
        }
Exemplo n.º 2
0
		/// <summary>
		/// Converts an object into XML.
		/// </summary>
		/// <param name="value">The object to serialize.</param>
		/// <returns>A string containing the serialization of the given object.</returns>
		public string Serialize(object value)
		{
			if (value == null) throw new ArgumentNullException("value");

			lock (_lockObject) // Don't allow reentrance
			{
				_visitedObjects = new ObjectXmlReferences();
				_typeCache = new Dictionary<Type, int>();

				var document = new XDocument(WriteValue(XmlConstants.ROOT, null, value));
				if (document.Root != null)
					document.Root.AddFirst(WriteTypeCache());
				string result = ConvertDocumentToString(document);

				CleanUp();

				return result;
			}
		}
Exemplo n.º 3
0
		private void CleanUp()
		{
			_visitedObjects.Clear();
			_visitedObjects = null;
		}
Exemplo n.º 4
0
 private void CleanUp()
 {
     _visitedObjects.Clear();
     _visitedObjects = null;
 }