コード例 #1
0
		/// <summary>
		/// Deserializes the specified <see cref="Object"/> from the specified path.
		/// </summary>
		/// <param name="obj">Specifies the <see cref="Object"/> to deserialize. Can be <see langword="null"/>.</param>
		/// <param name="stream">Specifies the <see cref="Stream"/> to deserialize from.</param>
		/// <param name="application">Specifies the name of the application that serialized the specified <see cref="T:Object"/>.</param>
		/// <exception cref="T:System.ArgumentNullException">
		/// <paramref name="stream"/> is <see langword="null"/>.
		/// </exception>
		public void Deserialize(object obj, Stream stream, string application)
		{
			if (stream == null)
			{
				throw new ArgumentNullException("stream");
			}

			CultureInfo currentCulture = Application.CurrentCulture;
			NuGenXmlTextReader xmlTextReader = null;

			try
			{
				Application.CurrentCulture = NuGenCulture.enUS;
				xmlTextReader = new NuGenXmlTextReader(stream);

				while (xmlTextReader.Read())
				{
					if (xmlTextReader.IsStartElement() && xmlTextReader.Name == this.Name)
					{
						_graph = new NuGenGraph();
						_references = new NuGenReferenceCollection();

						_graph.Add(obj);

						string applicationName = xmlTextReader.GetAttribute(Resources.XmlAttribute_Application);

						if (applicationName.Equals(application))
						{
							this.DeserializeObject(obj, this.DeserializeObject(xmlTextReader));
							this.SetReferenceDeserializing();
						}

						return;
					}

					xmlTextReader.Read();
				}
			}
			catch
			{
				throw;
			}
			finally
			{
				Application.CurrentCulture = currentCulture;

				if (xmlTextReader != null)
				{
					xmlTextReader.Close();
				}
			}
		}
コード例 #2
0
		public void Serialize(object obj, Stream stream, string application)
		{
			if (stream == null)
			{
				throw new ArgumentNullException("stream");
			}

			CultureInfo currentCulture = Application.CurrentCulture;

			try
			{
				Application.CurrentCulture = NuGenCulture.enUS;

				NuGenXmlTextWriter writer = new NuGenXmlTextWriter(stream);

				writer.WriteStartDocument(true);
				writer.WriteStartElement(this.Name);
				writer.WriteAttributeString(Resources.XmlAttribute_Version, this.Version);
				writer.WriteAttributeString(Resources.XmlAttribute_Version, application);

				_graph = new NuGenGraph();
				_references = new NuGenReferenceCollection();

				NuGenPropertyInfoCollection propertyInfoCollection = this.SerializeObject(obj);

				this.SetReferenceSerializing();

				this.SerializeObject(writer, propertyInfoCollection);

				writer.WriteEndElement();
				writer.Flush();
			}
			catch
			{
				throw;
			}
			finally
			{
				Application.CurrentCulture = currentCulture;
			}
		}