這是可能的,我用TFS2010,並在互聯網上找到它somehwere以下,它會打開SourceControlFileSelector:
VersionControlServer versionControlServer = (VersionControlServer)tfsConnection.GetService(typeof(VersionControlServer));
Assembly controlsAssembly = Assembly.GetAssembly(typeof(Microsoft.TeamFoundation.VersionControl.Controls.ControlAddItemsExclude));
Type vcChooseItemDialogType = controlsAssembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogChooseItem");
ConstructorInfo ci = vcChooseItemDialogType.GetConstructor(
BindingFlags.Instance | BindingFlags.NonPublic,
null,
new Type[] { typeof(VersionControlServer) },
null);
_chooseItemDialog = (Form)ci.Invoke(new object[] { versionControlServer });
_chooseItemDialog.ShowDialog();
this.DialogResult = _chooseItemDialog.DialogResult;
_selectItemProperty = vcChooseItemDialogType.GetProperty("SelectedItem", BindingFlags.Instance | BindingFlags.NonPublic);
Item selectedItem = (Item)_selectItemProperty.GetValue(_chooseItemDialog, null);
對於TFS2012有一些對話框直接使用,如TeamProjectPicker:
TeamProjectPicker dp = new TeamProjectPicker(TeamProjectPickerMode.NoProject, false);
DialogResult dr = dp.ShowDialog();
if (dr.Equals(DialogResult.OK) && dp.SelectedTeamProjectCollection != null)
{
Name = dp.SelectedTeamProjectCollection.ConfigurationServer.Name;
configTfsUrl = dp.SelectedTeamProjectCollection.ConfigurationServer.Uri.AbsoluteUri;
tfsUrl = dp.SelectedTeamProjectCollection.Uri;
}
因此,有對TFS2010沒有「官方」的方式,避免使用反映離子? –
不幸的是我從來沒有見過一個。即使是我只看過一次的反射方式。 – MikeR