ManagementReferenceAttribute Klasa

Definicja

Właściwość ManagementReferenceAttribute oznacza składową klasy, właściwość lub parametr metody jako odwołanie do innego obiektu lub klasy zarządzania.

Uwaga: biblioteki usługi WMI .NET są teraz brane pod uwagę w stanie końcowym, a żadne dalsze ulepszenia, ulepszenia ani aktualizacje nie będą dostępne w przypadku problemów związanych z zabezpieczeniami, które mają wpływ na te biblioteki.

public ref class ManagementReferenceAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false)]
public sealed class ManagementReferenceAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false)>]
type ManagementReferenceAttribute = class
    inherit Attribute
Public NotInheritable Class ManagementReferenceAttribute
Inherits Attribute
Dziedziczenie
ManagementReferenceAttribute
Atrybuty

Przykłady

W tym przykładzie pokazano, jak używać atrybutu ManagementReferenceAttribute razem z elementem ManagementQualifierAttribute , aby utworzyć klasę WMI skojarzenia, która łączy dwie inne klasy WMI. Przykładem jest odłączony dostawca, który uwidacznia trzy klasy WMI w przestrzeni nazw katalogu głównego/assoc. Dwie pierwsze klasy, NumberPhonetic i NumberLetter, są połączone przez ostatnią klasę LetterPhonetic.

Aby skompilować przykład, należy dołączyć odwołania do zarówno System.Management.Instrumentation, jak i System.Configuration.Install. Należy uruchomić installutil.exe względem wynikowego pliku wykonywalnego i upewnić się, że program jest uruchomiony w celu korzystania z zaimplementowanych klas WMI.

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;
        }

    }

}

Uwagi

Tego atrybutu można użyć do utworzenia klas skojarzeń, jak pokazano w poniższym przykładzie.

Konstruktory

Nazwa Opis
ManagementReferenceAttribute()

Inicjuje nowe wystąpienie klasy ManagementReferenceAttribute. Jest to konstruktor bez parametrów.

Właściwości

Nazwa Opis
Type

Pobiera lub ustawia nazwę przywołynego typu.

TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego Attribute.

(Odziedziczone po Attribute)

Metody

Nazwa Opis
Equals(Object)

Zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
GetHashCode()

Zwraca kod skrótu dla tego wystąpienia.

(Odziedziczone po Attribute)
GetType()

Pobiera Type bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

Po zastąpieniu w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną dla klasy pochodnej.

(Odziedziczone po Attribute)
Match(Object)

Po zastąpieniu w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Object.

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

Nazwa Opis
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie obiektu, którego można użyć do uzyskania informacji o typie dla interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Zapewnia dostęp do właściwości i metod uwidocznionych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy