反映Microsoft.TeamFoundation.VersionControl.Controls程序集时找不到DialogWorkItemDetails方法

时间:2016-01-07 16:36:36

标签: c# tfs

我正在尝试利用Microsoft.TeamFoundation.VersionControl.Controls程序集中的现有Dialog,该程序集将显示已发送的TFS工作项的详细信息。我使用反射来执行此操作,方式与accessing the DialogChangesetDetails method used here类似。

但是,在创建程序集,数组对象以存储方法参数之后,使用.CreateInstance方法找不到DialogChangesetDetails方法:

var assembly = Assembly.GetAssembly(typeof (WorkItemPolicy));
            var args = new object[] {this, workItem, false};
            using (
                var dialog =
                    (Form)
                        assembly.CreateInstance(
                            "Microsoft.TeamFoundation.VersionControl.Controls.DialogWorkItemDetails", false,
                            BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Instance, null, args,
                            CultureInfo.CurrentCulture, null))
            {
                if (dialog == null) return;
                dialog.StartPosition = FormStartPosition.CenterParent;
                dialog.ShowDialog();
            }

为了确保我没有尝试以错误的方式使用该方法,我使用反射器来接收有关它的信息:

public DialogWorkItemDetails(System.Windows.Forms.IWin32Window parent, WorkItem workItem, bool allowModification)
    {
        this.m_workItem = workItem;
        this.m_allowModification = allowModification;
        this.m_workItemStartedOutModified = this.m_workItem.IsDirty;
        this.InitializeWindow();
        this.UpdateButtons();
        this.GetWorkItemDetails();
        new WpfDialogAssistant(this)
        {
            HelpTopic = "vs.tfc.sourcecontrol.DialogWorkItemDetails"
        }.SetOwner(parent.Handle);
    }

据我所知,我正在向方法发送正确的参数,包括父表单,工作项以及用户是否可以修改工作项。

您可以找到entire DialogWorkItemDetails reflected code here

1 个答案:

答案 0 :(得分:0)

事实证明,因为我试图访问Public方法,所以我不应该使用BindingFlag.NonPublic。我更新了它,并且因为Dialog不是一次性表格而不得不改变我的演员。

var assembly = Assembly.GetAssembly(typeof (WorkItemPolicy));
var args = new object[] {this, workItem, true};
var dialog =
    (Window)
        assembly.CreateInstance(
            "Microsoft.TeamFoundation.VersionControl.Controls.DialogWorkItemDetails", false,
            BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance, null, args,
            CultureInfo.CurrentCulture, null);

            if (dialog == null) return;
            dialog.ShowDialog();