ManagementReferenceAttribute Klasa

Definicja

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

Uwaga: biblioteki platformy .NET usługi WMI są teraz traktowane w stanie końcowym i nie będą dostępne żadne dalsze ulepszenia, ulepszenia ani aktualizacje dotyczące problemów niezwiązanych z zabezpieczeniami, które mają wpływ na te biblioteki. Interfejsy API mi mi powinny być używane do wszystkich nowych programowania.

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 oddzielony dostawca, który uwidacznia trzy klasy WMI w przestrzeni nazw root/assoc. Pierwsze dwie 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

ManagementReferenceAttribute()

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

Właściwości

Type

Pobiera lub ustawia nazwę typu, do których odwołuje się odwołanie.

TypeId

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

(Odziedziczone po Attribute)

Metody

Equals(Object)

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

(Odziedziczone po Attribute)
GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

(Odziedziczone po Attribute)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

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

(Odziedziczone po Attribute)
Match(Object)

Po przesłonięciu 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 Objectelementu .

(Odziedziczone po Object)
ToString()

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

(Odziedziczone po Object)

Jawne implementacje interfejsu

_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 dla obiektu, który może służyć do pobierania 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)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy