Context 类
定义
为驻留在其中的对象定义环境,在此环境中可以实施策略。Defines an environment for the objects that are resident inside it and for which a policy can be enforced.
此 API 支持产品基础结构,不能在代码中直接使用。
public ref class Context
public class Context
[System.Runtime.InteropServices.ComVisible(true)]
public class Context
type Context = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type Context = class
Public Class Context
- 继承
-
Context
- 属性
注解
上下文是一系列有序属性,这些属性定义了其中驻留的对象的环境。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 as synchronization, transactions, just-in-time activation, security, and so on. 多个对象可以存留在一个上下文内。Multiple objects can live inside a context.
类使用类的实例进行标记 ContextAttribute ,该类提供使用规则。Classes are marked with an instance of the ContextAttribute class, which provides the usage rules. 每次实例化新的对象时,.NET Framework 会找到兼容的或为对象创建类的新实例 Context 。Whenever a new object is instantiated, the .NET Framework finds a compatible or creates a new instance of the Context class 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 by 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-context properties (also known as configuration properties) can be applied and configured by administrators.
有关上下文的详细信息,请参阅 边界:进程和应用程序域。For more information on contexts, see Boundaries: Processes and Application Domains.
构造函数
| Context() |
此 API 支持产品基础结构,不能在代码中直接使用。 初始化 Context 类的新实例。Initializes a new instance of the Context class. |
属性
| ContextID |
此 API 支持产品基础结构,不能在代码中直接使用。 获取当前上下文的上下文 ID。Gets the context ID for the current context. |
| ContextProperties |
此 API 支持产品基础结构,不能在代码中直接使用。 获取当前上下文属性的数组。Gets the array of the current context properties. |
| DefaultContext |
此 API 支持产品基础结构,不能在代码中直接使用。 获取当前应用程序域的默认上下文。Gets the default context for the current application domain. |
方法
| AllocateDataSlot() |
此 API 支持产品基础结构,不能在代码中直接使用。 分配未命名的数据槽。Allocates an unnamed data slot. |
| AllocateNamedDataSlot(String) |
此 API 支持产品基础结构,不能在代码中直接使用。 分配已命名的数据槽。Allocates a named data slot. |
| DoCallBack(CrossContextDelegate) |
此 API 支持产品基础结构,不能在代码中直接使用。 执行另一上下文中的代码。Executes code in another context. |
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| Finalize() |
此 API 支持产品基础结构,不能在代码中直接使用。 清理非默认上下文的后备对象。Cleans up the backing objects for the nondefault contexts. |
| FreeNamedDataSlot(String) |
此 API 支持产品基础结构,不能在代码中直接使用。 释放所有上下文中的命名数据槽。Frees a named data slot on all the contexts. |
| Freeze() |
此 API 支持产品基础结构,不能在代码中直接使用。 冻结上下文,使其无法从当前上下文添加或移除上下文属性。Freezes the context, making it impossible to add or remove context properties from the current context. |
| GetData(LocalDataStoreSlot) |
此 API 支持产品基础结构,不能在代码中直接使用。 从当前上下文上的指定槽检索值。Retrieves the value from the specified slot on the current context. |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetNamedDataSlot(String) |
此 API 支持产品基础结构,不能在代码中直接使用。 查找命名的数据槽。Looks up a named data slot. |
| GetProperty(String) |
此 API 支持产品基础结构,不能在代码中直接使用。 返回由名称指定的特定上下文属性。Returns a specific context property, specified by name. |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| RegisterDynamicProperty(IDynamicProperty, ContextBoundObject, Context) |
此 API 支持产品基础结构,不能在代码中直接使用。 用远程处理服务注册实现 IDynamicProperty 接口的动态属性。Registers a dynamic property implementing the IDynamicProperty interface with the remoting service. |
| SetData(LocalDataStoreSlot, Object) |
此 API 支持产品基础结构,不能在代码中直接使用。 设置当前上下文中的指定槽中的数据。Sets the data in the specified slot on the current context. |
| SetProperty(IContextProperty) |
此 API 支持产品基础结构,不能在代码中直接使用。 通过名称设置特定的上下文属性。Sets a specific context property by name. |
| ToString() |
此 API 支持产品基础结构,不能在代码中直接使用。 返回当前上下文的 String 类表示形式。Returns a String class representation of the current context. |
| UnregisterDynamicProperty(String, ContextBoundObject, Context) |
此 API 支持产品基础结构,不能在代码中直接使用。 注销实现 IDynamicProperty 接口的动态属性。Unregisters a dynamic property implementing the IDynamicProperty interface. |