viewstatearticle.cs

来自「该项目中对 SQLHelper 类进行了简单封装」· CS 代码 · 共 118 行

CS
118
字号
/* 
 * ViewStateArticle.cs @Microsoft Visual Studio 2005 <.NET Framework 2.0>
 * AfritXia
 * 2007-12-16
 * 
 * Copyright(c) http://www.AfritXia.NET/
 * 
 */

using System;
using System.Runtime.Serialization;

using NET.AfritXia.MyHome.Model.Message;

namespace NET.AfritXia.MyHome.HomeManagement.CodeLand.ModelProxy
{
	/// <summary>
	/// ViewState 版本的文章
	/// </summary>
	[Serializable]
	public class ViewStateArticle
	{
		// 文章 ID
		private int m_uniqueID;
		// 文章题目
		private string m_title;
		// 文章摘要
		private string m_summary;
		// 文章内容
		private string m_textContent;

		#region 类构造器
		/// <summary>
		/// 类参数构造器
		/// </summary>
		/// <param name="article"></param>
		public ViewStateArticle(Article article)
		{
			if (article == null)
			{
				// 清空文章 ID
				this.m_uniqueID = -1;
				// 文章题目
				this.m_title = null;
				// 文章摘要
				this.m_summary = null;
				// 文章内容
				this.m_textContent = null;
			}
			else
			{
				// 设置文章 ID
				this.m_uniqueID = article.UniqueID;
				// 文章题目
				this.m_title = article.Title;
				// 文章摘要
				this.m_summary = article.Summary;
				// 文章内容
				this.m_textContent = article.TextContent;
			}
		}

		/// <summary>
		/// 类 ViewStateArticle 参数构造器
		/// </summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		private ViewStateArticle(SerializationInfo info, StreamingContext context)
		{
			// 获取文章 ID
			this.m_uniqueID = info.GetInt32("uniqueID");
			// 获取文章题目
			this.m_title = info.GetString("title");
			// 获取文章摘要
			this.m_summary = info.GetString("summary");
			// 获取文章内容
			this.m_textContent = info.GetString("textContent");
		}
		#endregion

		#region ISerializable 成员
		public void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			// 设置文章 ID
			info.AddValue("uniqueID", this.m_uniqueID);
			// 设置文章题目
			info.AddValue("title", this.m_title);
			// 设置文章摘要
			info.AddValue("summary", this.m_summary);
			// 设置文章内容
			info.AddValue("textContent", this.m_textContent);
		}
		#endregion

		/// <summary>
		/// 恢复文章信息
		/// </summary>
		/// <returns></returns>
		public Article RestoreArticle()
		{
			if (this.m_uniqueID == -1)
				return null;

			Article article = new Article();

			// 设置文章 ID
			article.UniqueID = this.m_uniqueID;
			// 设置文章题目
			article.Title = this.m_title;
			// 设置文章摘要
			article.Summary = this.m_summary;
			// 设置文章内容
			article.TextContent = this.m_textContent;

			return article;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?