0
나는 투표를 한 다음 정렬 할 수있는 여러 클래스를 정의하는 추상 클래스가 있습니다. 이 클래스들은 모두 정렬 된 속성을 공유하기 때문에 이러한 속성으로 정렬 할 수있는 추상 수준의 메서드를 포함하고 싶습니다. 그러나 '매개 변수에 할당 할 수 없음'오류가 발생합니다. .추상 클래스의 객체 컬렉션에 정렬 메서드 사용
internal abstract class ESCO
{
public double HotScore { get; set; }
public double VoteTotal { get; set; }
public DateTime Created { get; set; }
protected static List<ESCO> SortedItems(List<ESCO> escoList, ListSortType sortType)
{
switch (sortType)
{
case ListSortType.Hot:
escoList.Sort(delegate(ESCO p1, ESCO p2) { return p2.HotScore.CompareTo(p1.HotScore); });
return escoList;
case ListSortType.Top:
escoList.Sort(delegate(ESCO p1, ESCO p2) { return p2.VoteTotal.CompareTo(p1.VoteTotal); });
return escoList;
case ListSortType.Recent:
escoList.Sort(delegate(ESCO p1, ESCO p2) { return p2.Created.CompareTo(p1.Created); });
return escoList;
default:
throw new ArgumentOutOfRangeException("sortType");
}
}
private SPUser GetCreatorFromListValue(SPListItem item)
{
var user = new SPFieldUserValue(SPContext.Current.Web, (string)item["Author"]);
return user.User;
}
private static VoteMeta InformationForThisVote(List<Vote> votes, int itemId)
{} // There are more methods not being shown with code to show why I used
// abstract instead of something else
}
같은 구현하는 시도 :
가 어떻게 다음 처리해야
class Post : ESCO
{
public string Summary { get; set; } // Properties in addition to abstract
public Uri Link { get; set; } // Properties in addition to abstract
public static List<Post> Posts(SPListItemCollection items, ListSortType sortType, List<Vote> votes)
{
var returnlist = new List<Post>();
for (int i = 0; i < items.Count; i++) { returnlist.Add(new Post(items[i], votes)); }
return SortedItems(returnlist, sortType);
}
나는 완전히 개방 나는 것은 "모든 잘못하고있어"합니다.
정확히 *는 오류지고있다, 그리고 당신이 그것을 어디에서 무엇을 얻을 수 있습니까 * 정확히 * *인가? –
마지막에 return 문이 있습니다. esco를 매개 변수로 할당 할 수 없게하기. – Wesley
인터페이스를 사용하여 기본 클래스 대신 정렬 할 수있는 속성을 정의 할 수 있습니다. 나는 상속이 "있는 것"관계라고 생각하고 인터페이스는 "할 수있다"물건을 정렬하는 데 사용됩니다. –