如何在代码审查页面的自定义部分中获取代码审查 ID?
How do I get the Code Review Id in a custom section of the code review page?
我正在编写一个 visual studio 扩展程序,它在代码审查页面上有一个部分。我想访问有关代码审查页面其余部分的信息,特别是正在显示的页面上当前的代码审查是什么。我应该能够访问 workitemId 但到目前为止我还没有弄清楚如何。
编辑
使用 Cole 的建议,我访问了 PageContent,但我不知道应该将内容转换为哪种类型。我也不知道它什么时候可用。我想在我初始化我的部分时和以后都访问。这是我尝试初始化该部分时的代码:
public override object SectionContent
{
get
{
if (base.SectionContent == null)
{
var teamExplorerPage = this.GetService<ITeamExplorerPage>();
var pageContent = teamExplorerPage.PageContent;
this.model.CodeReviewId = pageContent;
base.SectionContent = new CodePlusTeamExplorerSectionView(this.ServiceProvider, this.model);
}
return base.SectionContent;
}
}
当我调试代码时,我看到 PageContent 上有可用的 DataContext,但我不知道将 pageContent(或 ITeamExplorerPage)转换为什么类型才能访问它。此外,DataContext 有一个 CodeReviewId 属性,这似乎是我需要的值,但在生命周期的这一点上它是空的。如果我想根据 CodeReviewId when/where 检索一些额外的数据,它是否可用?
我仍在尝试弄清楚如何在页面的生命周期中更早地获取它,但是从页面中单击按钮之类的事件我可以使用反射检索值。这似乎有点 hack,也许其他人有更好的方法,但在这里。
private void Button_Click(object sender, RoutedEventArgs e)
{
var teamExplorer = this.GetService<ITeamExplorer>();
var currentPage = teamExplorer.CurrentPage;
var currentContent = currentPage.PageContent;
Type type = currentContent.GetType();
PropertyInfo pi = type.GetProperty("DataContext");
var dataContext = pi.GetValue(currentContent);
Type contextTypetype = dataContext.GetType();
PropertyInfo contextTypePi = contextTypetype.GetProperty("CodeReviewId");
var codeReviewId = contextTypePi.GetValue(dataContext);
var context = new Dictionary<string, object>();
context.Add("WorkItemId", codeReviewId);
teamExplorer.NavigateToPage(new Guid(TeamExplorerPageIds.ViewCodeReview), context);
}
我正在编写一个 visual studio 扩展程序,它在代码审查页面上有一个部分。我想访问有关代码审查页面其余部分的信息,特别是正在显示的页面上当前的代码审查是什么。我应该能够访问 workitemId 但到目前为止我还没有弄清楚如何。
编辑 使用 Cole 的建议,我访问了 PageContent,但我不知道应该将内容转换为哪种类型。我也不知道它什么时候可用。我想在我初始化我的部分时和以后都访问。这是我尝试初始化该部分时的代码:
public override object SectionContent
{
get
{
if (base.SectionContent == null)
{
var teamExplorerPage = this.GetService<ITeamExplorerPage>();
var pageContent = teamExplorerPage.PageContent;
this.model.CodeReviewId = pageContent;
base.SectionContent = new CodePlusTeamExplorerSectionView(this.ServiceProvider, this.model);
}
return base.SectionContent;
}
}
当我调试代码时,我看到 PageContent 上有可用的 DataContext,但我不知道将 pageContent(或 ITeamExplorerPage)转换为什么类型才能访问它。此外,DataContext 有一个 CodeReviewId 属性,这似乎是我需要的值,但在生命周期的这一点上它是空的。如果我想根据 CodeReviewId when/where 检索一些额外的数据,它是否可用?
我仍在尝试弄清楚如何在页面的生命周期中更早地获取它,但是从页面中单击按钮之类的事件我可以使用反射检索值。这似乎有点 hack,也许其他人有更好的方法,但在这里。
private void Button_Click(object sender, RoutedEventArgs e)
{
var teamExplorer = this.GetService<ITeamExplorer>();
var currentPage = teamExplorer.CurrentPage;
var currentContent = currentPage.PageContent;
Type type = currentContent.GetType();
PropertyInfo pi = type.GetProperty("DataContext");
var dataContext = pi.GetValue(currentContent);
Type contextTypetype = dataContext.GetType();
PropertyInfo contextTypePi = contextTypetype.GetProperty("CodeReviewId");
var codeReviewId = contextTypePi.GetValue(dataContext);
var context = new Dictionary<string, object>();
context.Add("WorkItemId", codeReviewId);
teamExplorer.NavigateToPage(new Guid(TeamExplorerPageIds.ViewCodeReview), context);
}