ManagementReferenceAttribute ManagementReferenceAttribute ManagementReferenceAttribute ManagementReferenceAttribute Class

Definición

ManagementReferenceAttribute marca un miembro de clase, propiedad o parámetro de método como una referencia a otro objeto o clase de administración.The ManagementReferenceAttribute marks a class member, property or method parameter as a reference to another management object or class.

Nota: Las bibliotecas .NET de WMI ahora se consideran en estado final y no estarán disponibles desarrollos posteriores, mejoras o actualizaciones para problemas no relacionados con la seguridad que afectan a estas bibliotecas.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. Las API de MI deben usarse para todo el nuevo desarrollo.The MI APIs should be used for all new development.

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

Ejemplos

En este ejemplo se muestra cómo utilizar ManagementReferenceAttribute el atributo junto ManagementQualifierAttribute con para crear una clase de WMI de asociación que vincule otras dos clases de WMI.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. El ejemplo es un proveedor desacoplado que expone tres clases WMI en el espacio de nombres root/Assoc.The example is a decoupled provider that exposes three WMI classes in the root/assoc namespace. Las dos primeras clases, NumberPhonetic y NumberLetter, están vinculadas por la última clase, LetterPhonetic.The first two classes, NumberPhonetic and NumberLetter, are linked by the last class, LetterPhonetic.

Para compilar el ejemplo, tendrá que incluir referencias a System. Management. Instrumentation y System. Configuration. Install.To compile the example, you will need to include references to both System.Management.Instrumentation and System.Configuration.Install. Debe ejecutar Installutil. exe en el ejecutable resultante y asegurarse de que el programa se está ejecutando con el fin de utilizar las clases WMI implementadas.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;  
        }  
  
    }  
  
}  

Comentarios

Puede usar este atributo para crear clases de asociación como se muestra en el ejemplo siguiente.You can use this attribute to create association classes as demonstrated in the following example.

Constructores

ManagementReferenceAttribute() ManagementReferenceAttribute() ManagementReferenceAttribute() ManagementReferenceAttribute()

Inicializa una nueva instancia de la clase ManagementReferenceAttribute.Initializes a new instance of the ManagementReferenceAttribute class. Este es el constructor sin parámetros.This is the parameterless constructor.

Propiedades

Type Type Type Type

Obtiene o establece el nombre del tipo al que se hace referencia.Gets or sets the name of the referenced type.

TypeId TypeId TypeId TypeId

Cuando se implementa en una clase derivada, obtiene un identificador único para este Attribute.When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

Métodos

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Devuelve un valor que indica si esta instancia es igual que un objeto especificado.Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Devuelve el código hash de esta instancia.Returns the hash code for this instance.

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

Si se reemplaza en una clase derivada, indica si el valor de esta instancia es el valor predeterminado de la clase derivada.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

Cuando se invalida en una clase derivada, devuelve un valor que indica si esta instancia es igual a un objeto especificado.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)

Implementaciones de interfaz explícitas

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

Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Obtiene la información de tipos de un objeto, que puede utilizarse para obtener la información de tipos de una interfaz.Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Proporciona acceso a las propiedades y los métodos expuestos por un objeto.Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

Se aplica a