📄 pageddatasource.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
namespace System.Web.UI.WebControls
{
/// <summary>
/// Summary description for PagedDataSource.
/// </summary>
public class PagedDataSource :System.Collections.ICollection,
System.Collections.IEnumerable,
System.ComponentModel.ITypedList
{
class EnumeratorOnArray : System.Collections.IEnumerator
{
private object[] array;
private int index;
private int indexBounds;
private int startIndex;
public EnumeratorOnArray(object[] array, int startIndex, int count)
{
this.array = array;
this.startIndex = startIndex;
this.index = -1;
this.indexBounds = startIndex + count;
if (this.indexBounds > (int) array.Length)
this.indexBounds = (int) array.Length;
}
public virtual void Reset()
{
this.index = -1;
}
public virtual bool MoveNext()
{
this.index = this.index + 1;
return this.startIndex + this.index < this.indexBounds;
}
public virtual object Current
{
get
{
if (this.index < 0)
throw new InvalidOperationException("Enumerator_MoveNext_Not_Called");
return this.array[this.startIndex + this.index];
}
}
}
class EnumeratorOnIList : System.Collections.IEnumerator
{
private int index;
private int indexBounds;
private int startIndex;
private System.Collections.IList collection;
public EnumeratorOnIList(IList collection, int startIndex, int count) : base()
{
this.collection = collection;
this.startIndex = startIndex;
this.index = -1;
this.indexBounds = startIndex + count;
if (this.indexBounds > collection.Count)
this.indexBounds = collection.Count;
}
public virtual bool MoveNext()
{
this.index = this.index + 1;
return this.startIndex + this.index < this.indexBounds;
}
public virtual void Reset()
{
this.index = -1;
}
public virtual object Current
{
get
{
if (this.index < 0)
throw new InvalidOperationException("Enumerator_MoveNext_Not_Called");
return this.collection[this.startIndex + this.index];
}
}
}
class EnumeratorOnICollection : System.Collections.IEnumerator
{
private int index;
private int indexBounds;
private int startIndex;
private System.Collections.ICollection collection;
private System.Collections.IEnumerator collectionEnum;
public EnumeratorOnICollection(ICollection collection, int startIndex, int count) : base()
{
this.collection = collection;
this.startIndex = startIndex;
this.index = -1;
this.indexBounds = startIndex + count;
if (this.indexBounds > collection.Count)
this.indexBounds = collection.Count;
}
public virtual bool MoveNext()
{
int local0;
if (this.collectionEnum == null)
{
this.collectionEnum = this.collection.GetEnumerator();
local0 = 0;
while (local0 < this.startIndex)
{
this.collectionEnum.MoveNext();
local0++;
}
}
this.collectionEnum.MoveNext();
this.index = this.index + 1;
return this.startIndex + this.index < this.indexBounds;
}
public virtual void Reset()
{
this.collectionEnum = null;
this.index = -1;
}
public virtual object Current
{
get
{
return this.collectionEnum.Current;
}
}
}
class EnumeratorOnIEnumerator : System.Collections.IEnumerator
{
private int index;
private int indexBounds;
private System.Collections.IEnumerator realEnum;
public EnumeratorOnIEnumerator(IEnumerator realEnum, int count) : base()
{
this.realEnum = realEnum;
this.index = -1;
this.indexBounds = count;
}
public virtual bool MoveNext()
{
bool local0;
local0 = this.realEnum.MoveNext();
this.index = this.index + 1;
if (local0)
return this.index < this.indexBounds;
return false;
}
public virtual void Reset()
{
this.realEnum.Reset();
this.index = -1;
}
public virtual object Current
{
get
{
return this.realEnum.Current;
}
}
}
private System.Collections.IEnumerable dataSource;
private int currentPageIndex;
private int pageSize;
private bool allowPaging;
private bool allowCustomPaging;
private int virtualCount;
public PagedDataSource()
{
//
// TODO: Add constructor logic here
//
}
public virtual PropertyDescriptorCollection GetItemProperties(System.ComponentModel.PropertyDescriptor[] listAccessors)
{
if (this.dataSource == null)
return null;
if (this.dataSource as ITypedList != null)
return ((ITypedList) this.dataSource).GetItemProperties(listAccessors);
return null;
}
public IEnumerable DataSource
{
get
{
return this.dataSource;
}
set
{
this.dataSource = value;
}
}
public virtual void CopyTo(Array array, int index)
{
IEnumerator local0;
local0 = this.GetEnumerator();
while (local0.MoveNext())
{
index = index + 1;
array.SetValue(local0.Current, index);
}
}
public virtual IEnumerator GetEnumerator()
{
int local0;
int local1;
local0 = this.FirstIndexInPage;
local1 = -1;
if (this.dataSource as ICollection != null)
local1 = this.Count;
if (this.dataSource as IList != null)
return new EnumeratorOnIList((IList) this.dataSource, local0, local1);
if (this.dataSource as Array != null)
return new EnumeratorOnArray((object[]) this.dataSource, local0, local1);
if (this.dataSource as ICollection != null)
return new EnumeratorOnICollection((ICollection) this.dataSource, local0, local1);
if (this.allowCustomPaging)
return new EnumeratorOnIEnumerator(this.dataSource.GetEnumerator(), this.Count);
return this.dataSource.GetEnumerator();
}
public virtual string GetListName(System.ComponentModel.PropertyDescriptor[] listAccessors)
{
return System.String.Empty;
}
public virtual int Count
{
get
{
if (this.dataSource == null)
return 0;
if (this.IsPagingEnabled)
{
if (this.IsCustomPagingEnabled || !(this.IsLastPage))
return this.pageSize;
return this.DataSourceCount - this.FirstIndexInPage;
}
return this.DataSourceCount;
}
}
public bool IsCustomPagingEnabled
{
get
{
if (this.IsPagingEnabled)
return this.allowCustomPaging;
return false;
}
}
public bool IsLastPage
{
get
{
if (this.IsPagingEnabled)
return this.CurrentPageIndex == this.PageCount - 1;
return true;
}
}
public virtual bool IsSynchronized
{
get
{
return false;
}
}
public bool IsPagingEnabled
{
get
{
if (this.allowPaging)
return this.pageSize != 0;
return false;
}
}
public virtual object SyncRoot
{
get
{
return this;
}
}
public int FirstIndexInPage
{
get
{
if (this.dataSource == null || !(this.IsPagingEnabled))
return 0;
if (this.IsCustomPagingEnabled)
return 0;
return this.currentPageIndex * this.pageSize;
}
}
public int CurrentPageIndex
{
get
{
return this.currentPageIndex;
}
set
{
this.currentPageIndex = value;
}
}
public int DataSourceCount
{
get
{
if (this.dataSource == null)
return 0;
if (this.IsCustomPagingEnabled)
return this.virtualCount;
if (this.dataSource as ICollection != null)
return ((ICollection)this.dataSource).Count;
throw new System.Web.HttpException(
System.Web.HttpRuntime.FormatResourceString("PagedDataSource_Cannot_Get_Count")
);
}
}
public int PageCount
{
get
{
int local0;
if (this.dataSource == null)
return 0;
local0 = this.DataSourceCount;
if (this.IsPagingEnabled && local0 != 0)
return local0 + this.pageSize - 1 / this.pageSize;
return 1;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -