ConstructionEnabledAttribute Klasse
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Ermöglicht COM+ Objektkonstruktionsunterstützung. 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
- 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
| Name | Beschreibung |
|---|---|
| ConstructionEnabledAttribute() |
Initialisiert eine neue Instanz der ConstructionEnabledAttribute Klasse und initialisiert die Standardeinstellungen für Enabled und Default. |
| ConstructionEnabledAttribute(Boolean) |
Initialisiert eine neue Instanz der ConstructionEnabledAttribute Klasse, die auf den angegebenen Wert festgelegt Enabled ist. |
Eigenschaften
| Name | Beschreibung |
|---|---|
| Default |
Dient zum Abrufen oder Festlegen eines Standardwerts für die Konstruktorzeichenfolge. |
| Enabled |
Dient zum Abrufen oder Festlegen eines Werts, der angibt, ob DIE COM+-Objektkonstruktionsunterstützung aktiviert ist. |
| TypeId |
Wenn sie in einer abgeleiteten Klasse implementiert wird, wird ein eindeutiger Bezeichner für diese Attribute. (Geerbt von Attribute) |
Methoden
| Name | Beschreibung |
|---|---|
| Equals(Object) |
Gibt einen Wert zurück, der angibt, ob diese Instanz einem angegebenen Objekt entspricht. (Geerbt von Attribute) |
| GetHashCode() |
Gibt den Hashcode für diesen instance zurück. (Geerbt von Attribute) |
| GetType() |
Ruft die Type der aktuellen Instanz ab. (Geerbt von Object) |
| IsDefaultAttribute() |
Wenn sie in einer abgeleiteten Klasse überschrieben wird, gibt an, ob der Wert dieser Instanz der Standardwert für die abgeleitete Klasse ist. (Geerbt von Attribute) |
| Match(Object) |
Wenn sie in einer abgeleiteten Klasse überschrieben wird, wird ein Wert zurückgegeben, der angibt, ob diese Instanz einem angegebenen Objekt entspricht. (Geerbt von Attribute) |
| MemberwiseClone() |
Erstellt eine flache Kopie der aktuellen Object. (Geerbt von Object) |
| ToString() |
Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt. (Geerbt von Object) |
Explizite Schnittstellenimplementierungen
| Name | Beschreibung |
|---|---|
| _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 denen 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) |
Bietet Zugriff auf Eigenschaften und Methoden, die von einem Objekt verfügbar gemacht werden. (Geerbt von Attribute) |