⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listitemcollection.cs

📁 不错的人事管理系统
💻 CS
字号:
/*
导读:
	这个类继承了多个接口,其中的System.Collections.IList的很多方法是私有实现的。也就是说,
	实现的方法只能通过该接口访问。如其中的int System.Collections.IList.Add(object)方法等。
	
	这个类实现了System.Web.UI.IStateManager接口,他使用System.Web.UI.Pair和System.Web.UI.Triplet
	两个类来实现保存ViewState。这是一个保存复杂的ViewState的办法。
	
	这个类实现了System.Collections.ICollection和System.Collections.IEnumerable,但并不自身提供
	实现,而是通过System.Collections.ArrayList提供的功能来实现,这是一种构造简单集合的办法。
*/
using System;

namespace System.Web.UI.WebControls
{
	/// <summary>
	/// Summary description for ListItemCollection.
	/// </summary>
	public class ListItemCollection : System.Collections.IList, 
		System.Collections.ICollection, 
		System.Collections.IEnumerable, 
		System.Web.UI.IStateManager
	{
		private System.Collections.ArrayList listItems;
		private bool marked;
		private bool saveAll;

		public ListItemCollection()
		{
			this.listItems = new System.Collections.ArrayList();
			this.marked = false;
			this.saveAll = false;
		}

		public void Add(ListItem item)
		{
			this.listItems.Add(item);
			if(this.marked)
			{
				item.Dirty = true;
			}
		}

		public void Add(string item)
		{
			this.Add(new ListItem(item));
		}

		internal object SaveViewState() //ok
		{
			int V_0;
			object[] V_1;
			object[] V_2;
			int V_3;
			System.Collections.ArrayList V_4;
			System.Collections.ArrayList V_5;
			int V_6;
			object V_7;

			if(this.saveAll)
			{
				V_0 = this.Count;
				V_1 = new string[V_0];
				V_2 = new string[V_0];

				for(V_3 = 0; V_3 < V_0; V_3 ++)
				{
					V_1[V_3] = this[V_3].Text;
					V_2[V_3] = this[V_3].Value;
				}

				return(new System.Web.UI.Triplet(V_0, V_1, V_2));
			}

			V_4 = new System.Collections.ArrayList(4);
			V_5 = new System.Collections.ArrayList(4);
			for(V_6=0; V_6 <this.Count; V_6++)
			{
				V_7 = this[V_6].SaveViewSate();
				if(V_7 != null)
				{
					V_4.Add(V_6);
					V_5.Add(V_7);
				}
			}

			if(V_4.Count >0)
			{
				return new System.Web.UI.Pair(V_4, V_5);
			}

			return(null);
		}

		internal void LoadViewState(object state)
		{
			System.Web.UI.Pair V_0;
			System.Collections.ArrayList V_1;
			System.Collections.ArrayList V_2;
			int V_3;
			int V_4;
			ListItem V_5;
			System.Web.UI.Triplet V_6;
			string[] V_7;
			string[] V_8;
			int V_9;

			if(state != null)
			{
				if(state is System.Web.UI.Pair)
				{
					V_0 = (System.Web.UI.Pair)state;
					V_1 = (System.Collections.ArrayList)V_0.First;
					V_2 = (System.Collections.ArrayList)V_0.Second;
					for(V_3 =0; V_3 <V_1.Count; V_3 ++)
					{
						V_4 = (int)V_1[V_3];
						if(V_4<this.Count)
						{
							this[V_4].LoadViewState(V_2[V_3]);
						}
						else
						{
							V_5 = new ListItem();
							V_5.LoadViewState(V_2[V_3]);
							this.Add(V_5);
						}
					}
					return;
				}

				V_6 = (System.Web.UI.Triplet)state;
				this.listItems = new System.Collections.ArrayList((int)V_6.First);
				this.saveAll = true;
				V_7 = (string[])V_6.Second;
				V_8 = (string[])V_6.Third;
				for(V_9 = 0; V_9 < V_7.Length; V_9++)
				{
					this.Add(new ListItem(V_7[V_9],V_8[V_9]));
				}
			}
		}

		internal void TrackViewState()
		{
			int V_0;
			this.marked = true;
			for(V_0 = 0; V_0<this.Count; V_0++)
			{
				this[V_0].TrackViewState();
			}
		}

		void  System.Web.UI.IStateManager.LoadViewState(object state)
		{
			this.LoadViewState(state);
		}

		object System.Web.UI.IStateManager.SaveViewState()
		{
			return this.SaveViewState();
		}

		void  System.Web.UI.IStateManager.TrackViewState()
		{
			this.TrackViewState();
		}

		bool  System.Web.UI.IStateManager.IsTrackingViewState
		{
			get
			{
				return(this.marked);
			}
		}

		public void AddRange(ListItem[] items)
		{
			ListItem V_0;
			ListItem[] V_1;
			int V_2;

			if(items == null)
			{
				throw new System.ArgumentNullException("items");
			}

			V_1 = items;
			for(V_2 = 0; V_2 <V_1.Length; V_2 ++)
			{
				V_0 = V_1[V_2];
				this.Add(V_0);
			}
		}

		public void Clear()
		{
			this.listItems.Clear();
			if(this.marked)
			{
				this.saveAll = true;
			}
		}

		public bool Contains(ListItem item)
		{
			return(this.listItems.Contains(item));
		}

		public void CopyTo(System.Array array, int index)
		{
			this.listItems.CopyTo(array,index);
		}

		public System.Collections.IEnumerator GetEnumerator()
		{
			return this.listItems.GetEnumerator();
		}

		public int IndexOf(ListItem item)
		{
			return(this.listItems.IndexOf(item));
		}

		public void Insert(int index, ListItem item)
		{
			this.listItems.Insert(index, item);
			if(this.marked)
			{
				this.saveAll = true;
			}
		}

		public void Remove(ListItem item)
		{
			int V_0;
			V_0 = this.IndexOf(item);
			if(V_0 >=0)
			{
				this.RemoveAt(V_0);
			}
		}

		public void Remove(string item)
		{
			int V_0;
			V_0 = this.IndexOf(new ListItem(item));
			if(V_0 >=0)
			{
				this.RemoveAt(V_0);
			}
		}

		public void RemoveAt(int index)
		{
			this.listItems.RemoveAt(index);

			if(this.marked)
			{
				this.saveAll = true;
			}
		}

		int System.Collections.IList.Add(object item)
		{
			ListItem V_0;
			int V_1;

			V_0 = (ListItem)item;

			V_1 = this.listItems.Add(V_0);

			if(this.marked)
			{
				V_0.Dirty = true;
			}

			return(V_1);
		}

		bool System.Collections.IList.Contains(object item)
		{
			return(this.Contains((ListItem)item));
		}

		int System.Collections.IList.IndexOf(object item)
		{
			return(this.IndexOf((ListItem)item));
		}

		void System.Collections.IList.Insert(int index, object item)
		{
			this.Insert(index,(ListItem)item);
		}

		bool  System.Collections.IList.IsFixedSize
		{
			get
			{
				return(false);
			}
		}

		object System.Collections.IList.this[int index]
		{
			get
			{
				return(this.listItems[index]);
			}
			set
			{
				this.listItems[index] = (ListItem)value;
			}
		}

		void  System.Collections.IList.Remove(object item)
		{
			this.Remove((ListItem)item);
		}

		public int Count
		{
			get
			{
				return(this.listItems.Count);
			}
		}

		public bool IsReadOnly
		{
			get
			{
				return(this.listItems.IsReadOnly);
			}
		}

		public bool IsSynchronized
		{
			get
			{
				return this.listItems.IsSynchronized;
			}
		}

		public void Capacity(int value)
		{
			this.listItems.Capacity = value;
		}

		public object SyncRoot
		{
			get
			{
				return(this);
			}
		}

		public ListItem this[int index]
		{
			get
			{
				return((ListItem)this.listItems[index]);
			}
		}

		public ListItem FindByText(string text) 
		{
			int local0;

			local0 = this.FindByTextInternal(text);
			if (local0 != -1)
				return (ListItem) this.listItems[local0];
			return null;
		}


		internal int FindByTextInternal(string text) 
		{
			int local0;

			local0 = 0;

			foreach(ListItem local1 in this.listItems)
			{
				if (local1.Text == text) 
				{
					return local0;
				}
				local0++;
			}

			return -1;
			
		}


		public ListItem FindByValue(string text) 
		{
			int local0;

			local0 = this.FindByValueInternal(text);
			if (local0 != -1)
				return (ListItem) this.listItems[local0];
			return null;
		}


		internal int FindByValueInternal(string value) 
		{
			int local0;

			local0 = 0;

			foreach(ListItem local1 in this.listItems)
			{
				if (local1.Value == value) 
				{
					return local0;
				}
				local0++;
			}

			return -1;
			
		}
	}
}

⌨️ 快捷键说明

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