Jonno 的回答非常有帮助而且很准确。我继续创建了一个代码片段,用于使用反射来调用对话框(在 TFS 2010 SP1 中适用于我)。希望它对有同样问题的其他人有用。如前所述,不保证此方法在任何未来版本中都可以正常工作。
public class TfsHistoryDialogWrapper
{
private readonly Type _dialogHistoryType;
private readonly object _historyDialogInstance;
public TfsHistoryDialogWrapper(VersionControlServer versionControl, string historyItem, VersionSpec itemVersion, int itemDeletionId, RecursionType recursionType, VersionSpec versionFrom, VersionSpec versionTo, string userFilter, int maxVersions, bool? slotMode)
{
Assembly tfsAssembly = typeof(Microsoft.TeamFoundation.VersionControl.Controls.LocalPathLinkBox).Assembly;
_dialogHistoryType = tfsAssembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogHistory");
_historyDialogInstance = _dialogHistoryType.GetConstructor(
BindingFlags.NonPublic | BindingFlags.Instance,
null,
new Type[]{typeof(VersionControlServer), typeof(string), typeof(VersionSpec), typeof(int), typeof(RecursionType), typeof(VersionSpec), typeof(VersionSpec), typeof(string), typeof(int), typeof(bool?)},
null).Invoke(new object[]{ versionControl, historyItem, itemVersion, itemDeletionId, recursionType, versionFrom, versionTo, userFilter, maxVersions, slotMode });
}
public void ShowDialog()
{
_dialogHistoryType.GetMethod("ShowDialog", new Type[]{}).Invoke(_historyDialogInstance, new object[]{});
}
}