2017-08-15 35 views
0

我正在編寫一個在代碼審查頁面上有一節的visual studio擴展。我想訪問有關代碼評論頁面其餘部分的信息,特別是要顯示的頁面上最新的代碼評論。我應該可以訪問workitemId,但到目前爲止我還沒有弄清楚如何。如何在代碼審閱頁面的自定義部分中獲取代碼審閱ID?

編輯 使用科爾的建議,我已訪問了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; 
     } 
    } 

當我調試的代碼,我看到一個DataContext是可在PageContent,但我不知道是什麼類型的pageContent(orITeamExplorerPage)投給,以獲得訪問權限。另外DataContext有一個CodeReviewId屬性,它看起來像我需要的值,但在生命週期的這一點它是空的。如果我想根據CodeReviewId檢索一些額外的數據何時何地可用?

+0

請您提供相關的屏幕快照有關代碼審查的ID,另外,請檢查是否可以通過使用ITeamExplorerPage.PageContent https://msdn.microsoft.com/en-us/library/檢索相關內容microsoft.teamfoundation.controls.iteamexplorerpage.pagecontent(v = vs.110)的.aspx –

回答

0

我仍然試圖弄清楚如何在頁面的生命週期中更早地獲取它,但是從頁面中的按鈕單擊事件我可以使用反射檢索值。這似乎有點破解,也許別人有更好的辦法,但現在就是這樣。

 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); 
    }