Share via


How to Reference Enumerations

Applies To: System Center 2012 - Service Manager

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Enumeration types are referenced through the standard ManagementPackProperty type. When you create a property and set it to the int type, you give it an integer value. Likewise, setting a property’s type to enum signifies that this property will be used as an enumeration.

By default, sccore does not know which enumeration type to use for this property and it must be supplied. You can specify the type of enumeration by getting reference an existing enumeration type, and then setting the EnumType property of the property object to that enumeration reference. The enumeration type referenced by a property should have child enumerations defined, which the property, when setting a value, will use. For more information, see How to Define an Enumeration.

To create a property as an enumeration

  1. Get reference to a management pack.

  2. Get reference to a management pack class.

  3. Get reference to an enumeration type.

  4. Create a new instance of the ManagementPackProperty class using the management pack class object.

  5. Set the DisplayName and Description properties.

  6. Set the Type property to enum.

  7. Add the property instance to the PropertyCollection property of the class.

  8. Set the management pack class Status property to PendingUpdate.

  9. Call the AcceptChanges method on the management pack.

Example

The following example demonstrates creating a property that references an enumeration type:

EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost");
ManagementPack mp = new ManagementPack("Folder\\RePackaging.Library.xml", mg);
ManagementPackClass mpClass = mp.GetClass("RePackaging.Request");
ManagementPackProperty mpProp = new ManagementPackProperty(mpClass, "PackagingStatus");
ManagementPackEnumeration mpEnum = mp.GetEnumeration("Enum.RePackagingStatus");

mpProp.Type = ManagementPackEntityPropertyTypes.@enum;
mpProp.EnumType = mpEnum;

mpClass.PropertyCollection.Add(mpProp);
mpClass.Status = ManagementPackElementStatus.PendingUpdate;

mp.AcceptChanges();

The following example demonstrates what the management pack XML elements should look like:

<ManagementPack ContentReadable="true" SchemaVersion="1.1" OriginalSchemaVersion="1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <Manifest>
    <Identity>
      <ID>RePackaging.Library</ID>
      <Version>1.0.0.0</Version>
    </Identity>
    <Name>RePackaging Library</Name>
    <References>
      <Reference Alias="WorkItem">
        <ID>System.WorkItem.Library</ID>
        <Version>7.0.6555.0</Version>
        <PublicKeyToken>9396306c2be7fcc4</PublicKeyToken>
      </Reference>
    </References>
  </Manifest>
  <TypeDefinitions>
    <EntityTypes>
      <ClassTypes>
        <ClassType ID="RePackaging.Request" Accessibility="Public" Abstract="false" Base="WorkItem!System.WorkItem" Hosted="false" Singleton="false" Extension="false">
          <Property ID="Requester" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false" />
          <Property ID="SoftwareTitle" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false" />
          <Property ID="BitsURI" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false" />
          <Property ID="PackagingStatus" Type="enum" Required="true" EnumType="Enum.RePackagingStatus" DefaultValue="Enum.RePackagingStatus.None" />
        </ClassType>
      </ClassTypes>
      <EnumerationTypes>
        <EnumerationValue ID="Enum.RePackagingStatus" Accessibility="Public" />
        <EnumerationValue ID="Enum.RePackagingStatus.None" Accessibility="Public" Parent="Enum.RePackagingStatus" />
        <EnumerationValue ID="Enum.RePackagingStatus.Requested" Accessibility="Public" Parent="Enum.RePackagingStatus" />
        <EnumerationValue ID="Enum.RePackagingStatus.Processing" Accessibility="Public" Parent="Enum.RePackagingStatus" />
        <EnumerationValue ID="Enum.RePackagingStatus.Completed" Accessibility="Public" Parent="Enum.RePackagingStatus" />
      </EnumerationTypes>
    </EntityTypes>
  </TypeDefinitions>
  <LanguagePacks>
    <LanguagePack ID="ENU" IsDefault="false">
      <DisplayStrings>
        <DisplayString ElementID="RePackaging.Request" SubElementID="Requester">
          <Name>Requester</Name>
          <Description>The name of the person requesting the software.</Description>
        </DisplayString>
        <DisplayString ElementID="RePackaging.Request" SubElementID="SoftwareTitle">
          <Name>Software Title</Name>
          <Description>The title of the software.</Description>
        </DisplayString>
        <DisplayString ElementID="RePackaging.Request" SubElementID="BitsURI">
          <Name>Software Location</Name>
          <Description>The URI of the software.</Description>
        </DisplayString>
        <DisplayString ElementID="RePackaging.Request" SubElementID="PackagingStatus">
          <Name>Packaging Request Status</Name>
        </DisplayString>
        <DisplayString ElementID="Enum.RePackagingStatus.None">
          <Name>None</Name>
        </DisplayString>
        <DisplayString ElementID="Enum.RePackagingStatus.Requested">
          <Name>Requested</Name>
        </DisplayString>
        <DisplayString ElementID="Enum.RePackagingStatus.Processing">
          <Name>Processing</Name>
        </DisplayString>
        <DisplayString ElementID="Enum.RePackagingStatus.Completed">
          <Name>Completed</Name>
        </DisplayString>
      </DisplayStrings>
    </LanguagePack>
  </LanguagePacks>
</ManagementPack>

Compiling the Code

Namespaces

Microsoft.EnterpriseManagement

Microsoft.EnterpriseManagement.Configuration

Assemblies

Microsoft.EnterpriseManagement.Core

See Also

Tasks

How to Define an Enumeration

Reference

ManagementPackProperty
ManagementPackEntityPropertyTypes
ManagementPackClass
ManagementPack
ManagementPackEnumeration

Other Resources

Scenario: Using Enumerations