First published on TECHNET on May 25, 2010
OK, so – you've figured out how to
create enumerations
(in
bulk even
),
use them in custom forms using the special ListPicker control
, how to
set enum property values
, and how to
add them to a form using form customization
. In this blog post, I'll show you how to manipulate enumerations programmatically using the SDK. Using this information you can create custom web forms, command line apps, PowerShell cmdlets, or Windows Workflow Foundation activities that need to manipulate enum data type properties.
Here are a few examples:
EnterpriseManagementGroup emg = new EnterpriseManagementGroup("localhost");
//Get all enumerations and list them in a list
foreach(ManagementPackEnumeration mpenum in emg.EntityTypes.GetEnumerations())
{
Console.WriteLine(mpenum.DisplayName);
}
//Get a specific enumeration by GUID
ManagementPackEnumeration mpenumIncidentUrgencyHigh = emg.EntityTypes.GetEnumeration(new Guid("2F8F0747-B6CB-7996-FD4A-84D09743F218"));
Console.WriteLine(mpenumIncidentUrgencyHigh.DisplayName);
//Get a specific enumeration by Name and MP
ManagementPack mpSystem = emg.ManagementPacks.GetManagementPack(SystemManagementPack.System);
Version verSystemVersion = mpSystem.Version;
string strSystemKeyToken = mpSystem.KeyToken;
ManagementPack mpWorkItemLibrary = emg.GetManagementPack("System.WorkItem.Library", strSystemKeyToken, verSystemVersion);
mpenumIncidentUrgencyHigh = emg.EntityTypes.GetEnumeration("System.WorkItem.TroubleTicket.UrgencyEnum.High",mpWorkItemLibrary);
Console.WriteLine(mpenumIncidentUrgencyHigh.DisplayName);
//Get a parent enumeration and enumerate all of its children
ManagementPackEnumerationCriteria mpenumcriteriaChildrenOfIncidentUrgencyParent = new ManagementPackEnumerationCriteria("Parent = '04B28BFB-8898-9AF3-009B-979E58837852'");
IList<ManagementPackEnumeration> listenumIncidentUrgency = emg.EntityTypes.GetEnumerations(mpenumcriteriaChildrenOfIncidentUrgencyParent);
foreach (ManagementPackEnumeration mpenumIncidentUrgency in listenumIncidentUrgency)
{
Console.WriteLine(mpenumIncidentUrgency.DisplayName);
}
Console application with examples can be downloaded from
here
.