0
我正在使用TFS API 2010.如何獲取TFS選項字段的選項列表?
我想獲得一個字段的可用選項列表來創建一個Combobox控件。如:
優先級 - > [1,2,3,4] 嚴重性 - > ['4-low','3-medium','2-height','1-Critical']
我正在使用TFS API 2010.如何獲取TFS選項字段的選項列表?
我想獲得一個字段的可用選項列表來創建一個Combobox控件。如:
優先級 - > [1,2,3,4] 嚴重性 - > ['4-low','3-medium','2-height','1-Critical']
您將需要從TFS中導出WorkItemType Definition,然後在xml中找到該字段並使用這些值。下面是我用來獲取轉換列表的代碼片段,如果您認爲這些選項可能位於全局列表中,那麼您將將export方法中的標誌設置爲true。
public List<Transition> GetTransistions(WorkItemType workItemType)
{
List<Transition> currentTransistions;
// See if this WorkItemType has already had it's transistions figured out.
this._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 newTransitions = new List<Transition>();
// get the transitions node.
XmlNodeList transitionsList = workItemTypeXml.GetElementsByTagName("TRANSITIONS");
// As there is only one transitions item we can just get the first
XmlNode transitions = transitionsList[0];
// Iterate all the transitions
foreach (XmlNode transition in transitions)
{
// save off the transition
newTransitions.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.
this._allTransistions.Add(workItemType, newTransitions);
return newTransitions;
}
過渡是一個小類,我有如下。
public class Transition
{
#region Public Properties
public string From { get; set; }
public string To { get; set; }
#endregion
}