ConstructionEnabledAttribute Klasse

Definition

Aktiviert die Konstruktionsunterstützung für COM+-Objekte. Diese Klasse kann nicht vererbt werden.

public ref class ConstructionEnabledAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, Inherited=true)]
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class ConstructionEnabledAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, Inherited=true)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
type ConstructionEnabledAttribute = class
    inherit Attribute
Public NotInheritable Class ConstructionEnabledAttribute
Inherits Attribute
Vererbung
ConstructionEnabledAttribute
Attribute

Beispiele

Im folgenden Codebeispiel wird die Verwendung dieses Attributs veranschaulicht, um eine Objektkonstruktorzeichenfolge einer ServicedComponent Klasse zuzuordnen.

// Accept a constructor string.

[ConstructionEnabled]
public ref class EmployeeInformation: public ServicedComponent
{
private:

   // The employee's user name and salary.
   String^ accountName;
   double salary;

public:

   // Get the employee's name. All users can call this method.
   String^ GetName()
   {
      return (accountName);
   }

   // Set the employee's salary. Only managers can do this.
   void SetSalary( double ammount )
   {
      if ( SecurityCallContext::CurrentCall->IsCallerInRole( "Manager" ) )
      {
         salary = ammount;
      }
      else
      {
         throw gcnew UnauthorizedAccessException;
      }
   }

   // Get the employee's salary. Only the employee and managers can do this.
   double GetSalary()
   {
      if ( SecurityCallContext::CurrentCall->DirectCaller->AccountName == accountName || SecurityCallContext::CurrentCall->IsCallerInRole( "Manager" ) )
      {
         return (salary);
      }
      else
      {
         throw gcnew UnauthorizedAccessException;
      }
   }

protected:
   // Use the constructor string.
   // This method is called when the object is instantiated.
   virtual void Construct( String^ constructorString ) override
   {
      accountName = constructorString;
   }
};
// Accept a constructor string.
[ConstructionEnabled]

public class EmployeeInformation : ServicedComponent
{

    // The employee's user name and salary.
    private string accountName;
    private double salary = 0;

    // Get the employee's name. All users can call this method.
    public string GetName ()
    {
      return(accountName);
    }

    // Set the employee's salary. Only managers can do this.
    public void SetSalary (double ammount)
    {
        if (SecurityCallContext.CurrentCall.IsCallerInRole("Manager"))
        {
            salary = ammount;
        }
        else
        {
            throw new UnauthorizedAccessException();
        }
    }

    // Get the employee's salary. Only the employee and managers can do this.
    public double GetSalary ()
    {
        if ( SecurityCallContext.CurrentCall.DirectCaller.AccountName == accountName ||
             SecurityCallContext.CurrentCall.IsCallerInRole("Manager") )
        {
            return(salary);
        }
        else
        {
          throw new UnauthorizedAccessException();
        }
    }

    // Use the constructor string.
    // This method is called when the object is instantiated.
    protected override void Construct (string constructorString)
    {
        accountName = constructorString;
    }
}
' Accept a constructor string.
<ConstructionEnabled()>  _
Public Class EmployeeInformation
    
    Inherits ServicedComponent
    
    ' The employee's user name and salary.
    Private accountName As String
    Private salary As Double = 0
    
    ' Get the employee's name. All users can call this method.
    Public Function GetName() As String 
        Return accountName
    
    End Function 'GetName
    
    ' Set the employee's salary. Only managers can do this.
    Public Sub SetSalary(ByVal ammount As Double) 
        If SecurityCallContext.CurrentCall.IsCallerInRole("Manager") Then
            salary = ammount
        Else
            Throw New UnauthorizedAccessException()
        End If
    
    End Sub
    
    ' Get the employee's salary. Only the employee and managers can do this.
    Public Function GetSalary() As Double 
        If SecurityCallContext.CurrentCall.DirectCaller.AccountName = accountName OrElse SecurityCallContext.CurrentCall.IsCallerInRole("Manager") Then
            Return salary
        Else
            Throw New UnauthorizedAccessException()
        End If
    
    End Function 'GetSalary
    
    ' Use the constructor string.
    ' This method is called when the object is instantiated.
    Protected Overrides Sub Construct(ByVal constructorString As String) 
        accountName = constructorString
    
    End Sub

End Class

Hinweise

Eine Liste der anfänglichen Eigenschaftswerte für eine Instanz von ConstructionEnabledAttribute, finden Sie im ConstructionEnabledAttribute Konstruktor.

Weitere Informationen zur Verwendung von Attributen finden Sie unter Attribute.

Konstruktoren

ConstructionEnabledAttribute()

Initialisiert eine neue Instanz der ConstructionEnabledAttribute-Klasse sowie die Standardeinstellungen für Enabled und Default.

ConstructionEnabledAttribute(Boolean)

Initialisiert eine neue Instanz der ConstructionEnabledAttribute-Klasse und legt Enabled auf den angegebenen Wert fest.

Eigenschaften

Default

Ruft einen Standardwert für die Konstruktorzeichenfolge ab oder legt diesen fest.

Enabled

Ruft einen Wert ab, der angibt, ob die Konstruktionsunterstützung für COM+-Objekte aktiviert ist, oder legt diesen fest.

TypeId

Ruft bei Implementierung in einer abgeleiteten Klasse einen eindeutigen Bezeichner für dieses Attribute ab.

(Geerbt von Attribute)

Methoden

Equals(Object)

Gibt einen Wert zurück, der angibt, ob diese Instanz gleich einem angegebenen Objekt ist.

(Geerbt von Attribute)
GetHashCode()

Gibt den Hashcode für diese Instanz zurück.

(Geerbt von Attribute)
GetType()

Ruft den Type der aktuellen Instanz ab.

(Geerbt von Object)
IsDefaultAttribute()

Gibt beim Überschreiben in einer abgeleiteten Klasse an, ob der Wert der Instanz der Standardwert für die abgeleitete Klasse ist.

(Geerbt von Attribute)
Match(Object)

Beim Überschreiben in einer abgeleiteten Klasse wird ein Wert zurückgegeben, der angibt, ob diese Instanz einem bestimmten Objekt entspricht.

(Geerbt von Attribute)
MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)

Explizite Schnittstellenimplementierungen

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

Ordnet eine Reihe von Namen einer entsprechenden Reihe von Dispatchbezeichnern zu.

(Geerbt von Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Ruft die Typinformationen für ein Objekt ab, mit deren Hilfe die Typinformationen für eine Schnittstelle abgerufen werden können.

(Geerbt von Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Ruft die Anzahl der Schnittstellen mit Typinformationen ab, die von einem Objekt bereitgestellt werden (0 oder 1).

(Geerbt von Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Stellt den Zugriff auf von einem Objekt verfügbar gemachte Eigenschaften und Methoden bereit.

(Geerbt von Attribute)

Gilt für