System.Runtime.Remoting.Contexts.Context Class

Assembly: Mscorlib.dll
Namespace: System.Runtime.Remoting.Contexts
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
Summary
Defines an environment for the objects that are resident inside it and for which a policy can be enforced.
C# Syntax:
public class Context
Remarks
A context is an ordered sequence of properties that define an environment for the objects resident inside it. Contexts get created during the activation process for objects that are configured to require certain automatic services such synchronization, transactions, just-in-time activation, security, and so on. Multiple objects can live inside a context.

Classes are marked with ContextAttribute, which provide the usage rules. Whenever a new object is instantiated, the .NET Framework finds a compatible or creates a new Context for the object. Once an object is placed in a context, it stays in it for life. Classes that can be bound to a context are called context-bound classes. When accessed from another context such classes are referenced directly using a proxy. Any call from an object in one context to an object in another context will go through a context proxy and be affected by the policy that the combined context properties enforce.

A new object's context is generally chosen based on meta-data attributes on the class. This mechanism is extensible through custom attributes. These are known as static context properties, which are compiled into the class meta-data. Dynamic (also known as configuration) context properties can be applied and configured by administrators.

For more information on contexts see the conceptual topic at MSDN: boundariesprocessesapplicationdomainscontexts.
See also:
System.Runtime.Remoting.Contexts Namespace

System.Runtime.Remoting.Contexts.Context Member List:

Public Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the Context class.
Public Properties
ContextID Read-only

Gets the context ID for the current Context.
ContextProperties Read-only

Gets the array of current context properties.
DefaultContext Read-only

Gets the default context for the current AppDomain.
Public Methods
AllocateDataSlot Allocates an un-named data slot.
AllocateNamedDataSlot Allocates a named data slot.
DoCallBack Executes code in another Context.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
FreeNamedDataSlot Frees a named data slot on all the contexts.
Freeze Freezes the context, making it impossible to add or remove context properties from the current Context.
GetData Retrieves the value from the specified slot on the current context.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetNamedDataSlot Looks up a named data slot.
GetProperty Returns a specific context property specified by name.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
RegisterDynamicProperty Registers a dynamic property implementing IDynamicProperty interface with the remoting service.
SetData Sets the data in the specified slot on the current context.
SetProperty Sets a specific context property by name.
ToString Overridden:
Returns a String representation of the current context.
UnregisterDynamicProperty Unregisters a dynamic property implementing IDynamicProperty.
Protected Methods
Finalize Overridden:
Cleans up the backing objects for the nondefault contexts.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Runtime.Remoting.Contexts.Context Member Details

ctor #1
Summary
Initializes a new instance of the Context class.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public Context();

Return to top


Property: ContextID (read-only)
Summary
Gets the context ID for the current Context.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public virtual int ContextID {get;}

Return to top


Property: ContextProperties (read-only)
Summary
Gets the array of current context properties.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public virtual IContextProperty[] ContextProperties {get;}

Return to top


Property: DefaultContext (read-only)
Summary
Gets the default context for the current AppDomain.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public static Context DefaultContext {get;}
Remarks
Every thread in an application domain for which a context is not explicitly set is considered to be running in the default context.

Return to top


Method: AllocateDataSlot()
Summary
Allocates an un-named data slot.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public static LocalDataStoreSlot AllocateDataSlot();
Return Value:
A local data slot.
Remarks
The slot is allocated on all the contexts.

Return to top


Method: AllocateNamedDataSlot(
   string name
)
Summary
Allocates a named data slot.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public static LocalDataStoreSlot AllocateNamedDataSlot(
   string name
);
Parameters:

name

The required for the data slot.

Return Value:
A local data slot object.
Remarks
The slot is allocated on all the contexts. Named data slots are "public" and can be manipulated by anyone.

Return to top


Method: DoCallBack(
   CrossContextDelegate deleg
)
Summary
Executes code in another Context.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public void DoCallBack(
   CrossContextDelegate deleg
);
Parameters:

deleg

The delegate used to request the callback.

Remarks
A callback can be done by calling the Context.DoCallBack method on it by passing in a delegate. The delegate is used to request a callback. The delegate must be of type CrossContextDelegate.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: Finalize()
Summary
Cleans up the backing objects for the nondefault contexts.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
~Context();
Remarks
For default contexts backing objects are cleaned up during AppDomain shutdown.

Return to top


Method: FreeNamedDataSlot(
   string name
)
Summary
Frees a named data slot on all the contexts.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public static void FreeNamedDataSlot(
   string name
);
Parameters:

name

The name of the data slot to free.

Remarks
Named data slots are "public" and can be manipulated by anyone.

Return to top


Method: Freeze()
Summary
Freezes the context, making it impossible to add or remove context properties from the current Context.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public virtual void Freeze();
Exceptions
Exception Type Condition
InvalidOperationException The Context is already frozen.
Remarks
Context properties cannot be added after the context has been frozen.

Return to top


Method: GetData(
   LocalDataStoreSlot slot
)
Summary
Retrieves the value from the specified slot on the current context.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public static object GetData(
   LocalDataStoreSlot slot
);
Parameters:

slot

The data slot that contains the data

Return Value:
Returns the data associated with the DataSlot provided

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetNamedDataSlot(
   string name
)
Summary
Looks up a named data slot.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public static LocalDataStoreSlot GetNamedDataSlot(
   string name
);
Parameters:

name

The data slot name.

Return Value:
Retruns a LocalDataSlot.
Remarks
If the name has not been used, a new slot is allocated. Named data slots are "public" and can be manipulated by anyone.

Return to top


Method: GetProperty(
   string name
)
Summary
Returns a specific context property specified by name.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public virtual IContextProperty GetProperty(
   string name
);
Parameters:

name

The name of the property

Return Value:
The specified context property.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: RegisterDynamicProperty(
   IDynamicProperty prop,
   ContextBoundObject obj,
   Context ctx
)
Summary
Registers a dynamic property implementing IDynamicProperty interface with the remoting service.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public static bool RegisterDynamicProperty(
   IDynamicProperty prop,
   ContextBoundObject obj,
   Context ctx
);
Parameters:

prop

The dynamic property to register.

obj

The object/proxy for which the property is registered. The object/proxy for which the property is registered.

ctx

The context for which the property is registered.

Return Value:
true if the property was successfully registered; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException The prop parameter or its name is null, or it is not dynamic (it does not implement IDynamicProperty).
ArgumentException Both an object as well as a context are specified (both obj and ctx parameters are not null).
Remarks
Based on the obj and ctx parameters, the property is asked to contribute a sink that is placed at some location in the path of remoting calls. If multiple properties are registered, their sinks will be called in an arbitrary order that can change between calls.

If the obj parameter is not null then if it is a proxy, all calls made on the proxy are intercepted. Otherwise, if obj is a real object, all calls on the object are intercepted. The ctx argument must be null.

If the ctx parameter is not null then the obj parameter must be null and all calls entering and leaving the context are intercepted.

If both ctx and obj parameters are null, then all calls entering and leaving all contexts are intercepted.

.NET Framework Security:
SecurityPermission for pluging code into the common language runtime infrastructure. Associated enumeration: SecurityPermissionFlag.Infrastructure.

Return to top


Method: SetData(
   LocalDataStoreSlot slot,
   object data
)
Summary
Sets the data in the specified slot on the current context.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public static void SetData(
   LocalDataStoreSlot slot,
   object data
);
Parameters:

slot

The data slot where the data is to be added.

data

The data that is to be added.

Return to top


Method: SetProperty(
   IContextProperty prop
)
Summary
Sets a specific context property by name.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public virtual void SetProperty(
   IContextProperty prop
);
Parameters:

prop

Actual context property.

Exceptions
Exception Type Condition
InvalidOperationException There is an attempt to add properties to the default context.
InvalidOperationException The context is frozen.
ArgumentNullException The property or the property name is null.
Remarks
Adding properties to the default context is not allowed.

Return to top


Overridden Method: ToString()
Summary
Returns a String representation of the current context.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public override string ToString();
Return Value:
A String representation of the current context.

Return to top


Method: UnregisterDynamicProperty(
   string name,
   ContextBoundObject obj,
   Context ctx
)
Summary
Unregisters a dynamic property implementing IDynamicProperty.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public static bool UnregisterDynamicProperty(
   string name,
   ContextBoundObject obj,
   Context ctx
);
Parameters:

name

The name of the dynamic property to unregister.

obj

The object/proxy for which the property is registered.

ctx

The context for which the property is registered.

Return Value:
true if the object was successfully unregistered; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException The name parameter is null.
ArgumentException Both an object as well as a context are specified (both obj and ctx parameters are not null).
.NET Framework Security:
SecurityPermission for pluging code into the common language runtime infrastructure. Associated enumeration: SecurityPermissionFlag.Infrastructure.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.