Export (0) Print
Expand All

ConstructionEnabledAttribute Class

Enables COM+ object construction support. This class cannot be inherited.

Namespace: System.EnterpriseServices
Assembly: System.EnterpriseServices (in system.enterpriseservices.dll)

[AttributeUsageAttribute(AttributeTargets.Class, Inherited=true)] 
[ComVisibleAttribute(false)] 
public sealed class ConstructionEnabledAttribute : 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

For a list of initial property values for an instance of ConstructionEnabledAttribute, see the ConstructionEnabledAttribute constructor.

For more information about using attributes, see Extending Metadata Using Attributes.

The following code example demonstrates the use of this attribute to associate an object constructor string with a ServicedComponent class.

// 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.
/** @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

System.Object
   System.Attribute
    System.EnterpriseServices.ConstructionEnabledAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft