Udostępnij za pośrednictwem


ManagementReferenceAttribute Klasa

Definicja

Parametr 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 WMI są teraz traktowane w stanie końcowym, a żadne dalsze ulepszenia, ulepszenia lub aktualizacje nie będą dostępne w przypadku problemów związanych z zabezpieczeniami, które mają wpływ na te biblioteki. Interfejsy API 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 odłączony dostawca, który uwidacznia trzy klasy WMI w przestrzeni nazw katalogu głównego/assoc. Pierwsze dwie klasy, NumberPhonetic i NumberLetter, są połączone przez ostatnią klasę LetterPhonetic.

Aby skompilować przykład, należy uwzględnić odwołania do programu System.Management.Instrumentation i System.Configuration.Install. Należy uruchomić installutil.exe względem wynikowego pliku wykonywalnego i upewnić się, że program jest uruchomiony w celu użycia 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ę przywołynego typu.

TypeId

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

(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 bieżące wystąpienie.

(Odziedziczone po Object)
IsDefaultAttribute()

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

(Odziedziczone po Attribute)
Match(Object)

W przypadku zastąpienia 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 obiektu, którego można użyć do pobrania informacji o typie 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