ConstructionEnabledAttribute Třída

Definice

Umožňuje podporu konstrukce objektů MODELU COM+. Tuto třídu nelze dědit.

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
Dědičnost
ConstructionEnabledAttribute
Atributy

Příklady

Následující příklad kódu ukazuje použití tohoto atributu k přidružení řetězce konstruktoru objektu ServicedComponent ke třídě.

// 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

Poznámky

Seznam počátečních hodnot vlastností pro instanci ConstructionEnabledAttributenaleznete v konstruktoru ConstructionEnabledAttribute .

Další informace o používání atributů najdete v tématu Atributy.

Konstruktory

ConstructionEnabledAttribute()

Inicializuje novou instanci ConstructionEnabledAttribute třídy a inicializuje výchozí nastavení pro Enabled a Default.

ConstructionEnabledAttribute(Boolean)

Inicializuje novou instanci ConstructionEnabledAttribute třídy, nastavení Enabled na zadanou hodnotu.

Vlastnosti

Default

Získá nebo nastaví výchozí hodnotu pro řetězec konstruktoru.

Enabled

Získá nebo nastaví hodnotu určující, zda je povolena podpora konstrukce objektů MODELU COM+.

TypeId

Při implementaci v odvozené třídě získá jedinečný identifikátor pro tento Attribute.

(Zděděno od Attribute)

Metody

Equals(Object)

Vrací hodnotu, která určuje, zda je tato instance rovna zadanému objektu.

(Zděděno od Attribute)
GetHashCode()

Vrátí hodnotu hash pro tuto instanci.

(Zděděno od Attribute)
GetType()

Type Získá aktuální instanci.

(Zděděno od Object)
IsDefaultAttribute()

Při přepsání v odvozené třídě určuje, zda hodnota této instance je výchozí hodnotou odvozené třídy.

(Zděděno od Attribute)
Match(Object)

Při přepsání v odvozené třídě vrátí hodnotu, která označuje, zda se tato instance rovná zadanému objektu.

(Zděděno od Attribute)
MemberwiseClone()

Vytvoří použádnou kopii aktuálního souboru Object.

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Explicitní implementace rozhraní

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

Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.

(Zděděno od Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Načte informace o typu objektu, který lze použít k získání informací o typu rozhraní.

(Zděděno od Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).

(Zděděno od Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Poskytuje přístup k vlastnostem a metodám vystaveným objektem.

(Zděděno od Attribute)

Platí pro