我有一个自定义集合PagedList<T>
正从我的WCF服务返回PagedListOfEntitySearchResultW_SH0Zpu5
当T EntitySearchResult对象。
我想在应用程序和服务之间重用这种PagedList<T>
类型。
我的情景:
我创建了一个PagedList<T>
类型从List<T>
继承。 此类型位于应用程序和WCF服务中引用的分离程序集上。
我正在使用scvutil上的/ reference选项来启用类型重用。我也不希望任何数组返回,因此我也使用/collection
映射到通用List类型。 我使用下面的命令svcutil
生成服务代理:
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\svcutil.exe"
/collectionType:System.Collections.Generic.List`1
/reference:..\..\bin\Debug\App.Utilities.dll
http://localhost/App.MyService/MyService.svc?wsdl
/namespace:*,"App.ServiceReferences.MyService"
/out:..\ServiceProxy\MyService.cs
的PagedList对象是一样的东西:
[CollectionDataContract]
public partial class PagedList<T> : List<T>
{
public PagedList() { }
/// <summary>
/// Creates a new instance of the PagedList object and doesn't apply any pagination algorithm.
/// The only calculated property is the TotalPages, everything else needed must be passed to the object.
/// </summary>
/// <param name="source"></param>
/// <param name="pageNumber"></param>
/// <param name="pageSize"></param>
/// <param name="totalRecords"></param>
public PagedList(IEnumerable<T> source, int pageNumber, int pageSize, int totalRecords)
{
if (source == null)
source = new List<T>();
this.AddRange(source);
PagingInfo.PageNumber = pageNumber;
PageSize = pageSize;
TotalRecords = totalRecords;
}
public PagedList(IEnumerable<T> source, PagingInfo paging)
{
this.AddRange(source);
this._pagingInfo = paging;
}
[DataMember]
public int TotalRecords { get; set; }
[DataMember]
public int PageSize { get; set; }
public int TotalPages()
{
if (this.TotalRecords > 0 && PageSize > 0)
return (int)Math.Ceiling((double)TotalRecords/(double)PageSize);
else
return 0;
}
public bool? HasPreviousPage()
{
return (PagingInfo.PageNumber > 1);
}
public bool? HasNextPage() { return (PagingInfo.PageNumber < TotalPages()); }
public bool? IsFirstPage() { return PagingInfo.PageNumber == 1; }
public bool? IsLastPage() { return PagingInfo.PageNumber == TotalPages(); }
PagingInfo _pagingInfo = null;
[DataMember]
public PagingInfo PagingInfo
{
get {
if (_pagingInfo == null)
_pagingInfo = new PagingInfo();
return _pagingInfo;
}
set
{
_pagingInfo = value;
}
}
}
所以问题真的是?!?!?..... – 2011-01-06 15:52:22