コード例 #1
0
//		/// <summary>
//		/// Gets the value to write using a BinaryFormatter to serialize the Object.Value property.
//		/// </summary>
//		/// <param name="option"></param>
//		/// <returns></returns>
//		private string GetSerializedValue(XmlConfigurationOption option)
//		{
//			string buffer = null;
//			try
//			{
//				/// this should really use reflection to determine if the type supports serialization
//				BinaryFormatter formatter = new BinaryFormatter();
//				MemoryStream stream = new MemoryStream();
//				formatter.Serialize(stream, option.Value);
//				buffer = System.Text.Encoding.ASCII.GetString(stream.GetBuffer());
//				stream.Close();
//			}
//			catch(Exception ex)
//			{
//				Debug.WriteLine(ex);
//				this.OnCannotWriteValue(this, new XmlConfigurationWriterEventArgs(ex, option));
//			}
//			return buffer;
//		}

        /// <summary>
        /// Raises the CannotWriteValue event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnCannotWriteValue(object sender, XmlConfigurationWriterEventArgs e)
        {
            try
            {
                if (this.CannotWriteValue != null)
                {
                    this.CannotWriteValue(sender, e);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
コード例 #2
0
//		/// <summary>
//		/// Gets the value to write using a BinaryFormatter to serialize the Object.Value property.
//		/// </summary>
//		/// <param name="option"></param>
//		/// <returns></returns>
//		private string GetSerializedValue(XmlConfigurationOption option)
//		{
//			string buffer = null;
//			try
//			{
//				/// this should really use reflection to determine if the type supports serialization				
//				BinaryFormatter formatter = new BinaryFormatter();
//				MemoryStream stream = new MemoryStream();
//				formatter.Serialize(stream, option.Value);
//				buffer = System.Text.Encoding.ASCII.GetString(stream.GetBuffer());
//				stream.Close();
//			}
//			catch(Exception ex)
//			{
//				Debug.WriteLine(ex);
//				this.OnCannotWriteValue(this, new XmlConfigurationWriterEventArgs(ex, option));
//			}
//			return buffer;
//		}

		/// <summary>
		/// Raises the CannotWriteValue event
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected virtual void OnCannotWriteValue(object sender, XmlConfigurationWriterEventArgs e)
		{
			try
			{
				if (this.CannotWriteValue != null)
					this.CannotWriteValue(sender, e);
			}
			catch(Exception ex)
			{
				Debug.WriteLine(ex);
			}
		}