VersionControlServer.QueryHistory返回System.Collections.IEnumerable / System.Collections.Generic.IEnumerable

时间:2016-02-04 03:10:40

标签: c# linq tfs2010

查看QueryHistory的{​​{1}}方法重载:

https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver.queryhistory.aspx?f=255&MSPPError=-2147217396

似乎有些重载会返回Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer 和其他人返回System.Collections.Generic.IEnumerable<Changeset>

有一种简单的方法可以将System.Collections.IEnumerable(包含System.Collections.IEnumerable项)转换为Changeset吗?

1 个答案:

答案 0 :(得分:1)

如果您确定该集合只包含ChangeSet项,则可以使用Linq扩展方法Cast()

IEnumerable myCollection = ...
IEnumerable<ChangeSet> myGenericCollection = myCollection.Cast<ChangeSet>();

如果您不完全确定该集合仅包含ChangeSet,则可以使用其他Linq扩展方法OfType()对其进行过滤:

IEnumerable myCollection = ...
IEnumerable<ChangeSet> myGenericCollection = myCollection.OfType<ChangeSet>();