ConstructionEnabledAttribute-Klasse
Aktiviert die Konstruktionsunterstützung für COM+-Objekte. Diese Klasse kann nicht vererbt werden.
Namespace: System.EnterpriseServices
Assembly: System.EnterpriseServices (in system.enterpriseservices.dll)
Syntax
'Declaration
<AttributeUsageAttribute(AttributeTargets.Class, Inherited:=True)> _
<ComVisibleAttribute(False)> _
Public NotInheritable Class ConstructionEnabledAttribute
Inherits Attribute
'Usage
Dim instance As ConstructionEnabledAttribute
[AttributeUsageAttribute(AttributeTargets.Class, Inherited=true)]
[ComVisibleAttribute(false)]
public sealed class ConstructionEnabledAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class, Inherited=true)]
[ComVisibleAttribute(false)]
public ref class ConstructionEnabledAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, Inherited=true) */
/** @attribute ComVisibleAttribute(false) */
public final class ConstructionEnabledAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class, Inherited=true)
ComVisibleAttribute(false)
public final class ConstructionEnabledAttribute extends Attribute
Hinweise
Eine Liste der anfänglichen Eigenschaftenwerte für eine Instanz von ConstructionEnabledAttribute finden Sie unter ConstructionEnabledAttribute-Konstruktor.
Weitere Informationen über das Verwenden von Attributen finden Sie unter Erweitern von Metadaten mithilfe von Attributen.
Beispiel
Im folgenden Codebeispiel wird veranschaulicht, wie dieses Attribut verwendet wird, um einer ServicedComponent-Klasse eine Objektkonstruktorzeichenfolge zuzuordnen.
' 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 'SetSalary
' 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 'Construct
End Class 'EmployeeInformation
// 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 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.
/** @attribute ConstructionEnabled()
*/
public class EmployeeInformation extends 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;
} //GetName
// Set the employee's salary. Only managers can do this.
public void SetSalary(double ammount)
throws System.UnauthorizedAccessException
{
if (SecurityCallContext.get_CurrentCall().IsCallerInRole("Manager")) {
salary = ammount;
}
else {
throw new UnauthorizedAccessException();
}
} //SetSalary
// Get the employee's salary. Only the employee and managers can do this.
public double GetSalary() throws System.UnauthorizedAccessException
{
if (SecurityCallContext.get_CurrentCall().get_DirectCaller().
get_AccountName().Equals(accountName)
|| SecurityCallContext.get_CurrentCall().
IsCallerInRole("Manager")) {
return salary;
}
else {
throw new UnauthorizedAccessException();
}
} //GetSalary
// Use the constructor string.
// This method is called when the object is instantiated.
protected void Construct(String constructorString)
{
accountName = constructorString;
} //Construct
} //EmployeeInformation
Vererbungshierarchie
System.Object
System.Attribute
System.EnterpriseServices.ConstructionEnabledAttribute
Threadsicherheit
Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.
Plattformen
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
ConstructionEnabledAttribute-Member
System.EnterpriseServices-Namespace