ManagementReferenceAttribute Class
 

The ManagementReferenceAttribute marks a class member, property or method parameter as a reference to another management object or class.

Note: the WMI .NET libraries are now considered in final state, and no further development, enhancements, or updates will be available for non-security related issues affecting these libraries. The MI APIs should be used for all new development.

Namespace:   System.Management.Instrumentation
Assembly:  System.Core (in System.Core.dll)

SystemObject
   SystemAttribute
    System.Management.InstrumentationManagementReferenceAttribute

[AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, 
	AllowMultiple = false)]
[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public sealed class ManagementReferenceAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Property | AttributeTargets::Field | AttributeTargets::Parameter, 
	AllowMultiple = false)]
[HostProtectionAttribute(SecurityAction::LinkDemand, MayLeakOnAbort = true)]
public ref class ManagementReferenceAttribute sealed : Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter,
    AllowMultiple = false)>]
[<HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)>]
type ManagementReferenceAttribute = 
    class
        inherit Attribute
    end
<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Parameter,
	AllowMultiple := False)>
<HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort := True)>
Public NotInheritable Class ManagementReferenceAttribute
	Inherits Attribute
NameDescription
System_CAPS_pubmethod ManagementReferenceAttribute

Initializes a new instance of the T:System.Management.ManagementReferenceAttribute class. This is the default constructor.

NameDescription
System_CAPS_pubproperty

Gets or sets the name of the referenced type.

System_CAPS_pubproperty

When implemented in a derived class, gets a unique identifier for this Attribute.(Inherited from Attribute.)

NameDescription
System_CAPS_pubmethod Equals

This API supports the product infrastructure and is not intended to be used directly from your code. Returns a value that indicates whether this instance is equal to a specified object.(Inherited from Attribute.)

System_CAPS_pubmethod GetHashCode

Returns the hash code for this instance.(Inherited from Attribute.)

System_CAPS_pubmethod GetType

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethod IsDefaultAttribute

When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.(Inherited from Attribute.)

System_CAPS_pubmethod Match

When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.(Inherited from Attribute.)

System_CAPS_pubmethod ToString

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubinterface System_CAPS_privmethod _AttributeGetIDsOfNames

Maps a set of names to a corresponding set of dispatch identifiers.(Inherited from Attribute.)

System_CAPS_pubinterface System_CAPS_privmethod _AttributeGetTypeInfo

Retrieves the type information for an object, which can be used to get the type information for an interface.(Inherited from Attribute.)

System_CAPS_pubinterface System_CAPS_privmethod _AttributeGetTypeInfoCount

Retrieves the number of type information interfaces that an object provides (either 0 or 1).(Inherited from Attribute.)

System_CAPS_pubinterface System_CAPS_privmethod _AttributeInvoke

Provides access to properties and methods exposed by an object.(Inherited from Attribute.)

You can use this attribute to create association classes as demonstrated in the following example.

This example demonstrates how to use the ManagementReferenceAttribute attribute together with the ManagementQualifierAttribute to create an association WMI class that links two other WMI classes. The example is a decoupled provider that exposes three WMI classes in the root/assoc namespace. The first two classes, NumberPhonetic and NumberLetter, are linked by the last class, LetterPhonetic.

To compile the example, you will need to include references to both System.Management.Instrumentation and System.Configuration.Install. You must run installutil.exe against the resulting executable and ensure that the program is running in order to use the implemented WMI classes.

using System;
using System.Collections;
using System.Management.Instrumentation;

[assembly: WmiConfiguration("root/assoc", HostingModel = ManagementHostingModel.Decoupled)]

[System.ComponentModel.RunInstaller(true)]
public class TheInstaller : DefaultManagementInstaller
{ }


namespace AssocExample
{
    class Program
    {
        static void Main(string[] args)
        {
            InstrumentationManager.RegisterType(typeof(NumberPhonetic));
            InstrumentationManager.RegisterType(typeof(NumberLetter));
            InstrumentationManager.RegisterType(typeof(LetterPhonetic));

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();

            InstrumentationManager.UnregisterType(typeof(NumberPhonetic));
            InstrumentationManager.UnregisterType(typeof(NumberLetter));
            InstrumentationManager.UnregisterType(typeof(LetterPhonetic));

        }
    }

  [ManagementEntity]
    public class NumberPhonetic
    {
        [ManagementKey]
        public int Number;

        [ManagementProbe]
        public string Name;

        [ManagementBind]
        public NumberPhonetic(int Number)
        {
           this.Number = Number;
           if(Number == 1)
           {
              Name = "alpha";
           }
           else if(Number == 2)
           {
              Name = "bravo";
           }
           else
           {
              throw new InstanceNotFoundException();
           }
        }

        [ManagementEnumerator]
        static public IEnumerable EnumerateInstances()
        {
            for (int i = 1; i < 3; i++)
            {
                yield return new NumberPhonetic(i);
            }
        }

    }

    [ManagementEntity]
    public class NumberLetter
    {
        [ManagementKey]
        public int Number;

        [ManagementProbe]
        public string Letter;

        [ManagementBind]
        public NumberLetter(int Number)
        {
           this.Number = Number;
           if(Number == 1)
           {
              Letter = "A";
           }
           else if(Number == 2)
           {
              Letter = "B";
           }
           else
           {
              throw new InstanceNotFoundException();
           }
        }

        [ManagementEnumerator]
        static public IEnumerable EnumerateInstances()
        {
            for (int i = 1; i < 3; i++)
            {
                yield return new NumberLetter(i);
            }
        }

    }

    [ManagementEntity]
    [ManagementQualifier("Association", Flavor = ManagementQualifierFlavors.DisableOverride)]
    public class LetterPhonetic
    {
        [ManagementReference(Type = "NumberLetter")]
        [ManagementKey]
        public string LetterNumber;

        [ManagementReference(Type = "NumberPhonetic")]
        [ManagementKey]
        public string PhoneticNumber;

        [ManagementEnumerator]
        static public IEnumerable EnumerateInstances()
        {
            ArrayList insts = new ArrayList();
            for (int i = 1; i < 3; i++)
            {
                LetterPhonetic inst = new LetterPhonetic();
                inst.LetterNumber = "Letter = " + i;
                inst.PhoneticNumber = "Phonetic = " + i;
                insts.Add(inst);
            }
            return insts;
        }

    }

}
.NET Framework
Available since 3.5

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top