Example #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);
            }
        }
		/// <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;
			}
		}
		private void CleanUp()
		{
			_visitedObjects.Clear();
			_visitedObjects = null;
		}
Example #4
0
 private void CleanUp()
 {
     _visitedObjects.Clear();
     _visitedObjects = null;
 }