gpt4 book ai didi

c# - TFS API - 有没有办法获取工作项类型的转换列表?

转载 作者:太空狗 更新时间:2023-10-29 18:30:30 24 4
gpt4 key购买 nike

我正在尝试从状态“A”到状态“X”。

有一些转换阻止我直接转到 X。

我可以将 WorkItemType 导出为 XML 并处理它,但在我这样做之前,我想我会问是否有办法通过 API 获取转换。

最佳答案

太好了......

没有多少人需要 WorkItemType 的转换。

好吧,我需要它,所以我写了一个方法来完成它。这是为了以防其他人需要这个:

// Hold a list of all the transistions we have done.  This will help us not have run them again If we already have.
private static Dictionary<WorkItemType, List<Transition>> _allTransistions = new Dictionary<WorkItemType, List<Transition>>();

/// <summary>
/// Get the transitions for this <see cref="WorkItemType"/>
/// </summary>
/// <param name="workItemType"></param>
/// <returns></returns>
private static List<Transition> GetTransistions(this WorkItemType workItemType)
{
List<Transition> currentTransistions;

// See if this WorkItemType has already had it's transistions figured out.
_allTransistions.TryGetValue(workItemType, out currentTransistions);
if (currentTransistions != null)
return currentTransistions;

// Get this worktype type as xml
XmlDocument workItemTypeXml = workItemType.Export(false);

// Create a dictionary to allow us to look up the "to" state using a "from" state.
var newTransistions = new List<Transition>();

// get the transistions node.
XmlNodeList transitionsList = workItemTypeXml.GetElementsByTagName("TRANSITIONS");

// As there is only one transistions item we can just get the first
XmlNode transitions = transitionsList[0];

// Iterate all the transitions
foreach (XmlNode transition in transitions)
{
// save off the transistion
newTransistions.Add(new Transition
{
From = transition.Attributes["from"].Value,
To = transition.Attributes["to"].Value
});

}

// Save off this transition so we don't do it again if it is needed.
_allTransistions.Add(workItemType, newTransistions);

return newTransistions;
}

public class Transition
{
public string To { get; set; }
public string From { get; set; }
}

关于c# - TFS API - 有没有办法获取工作项类型的转换列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2203506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com