MemberRelationshipService 类
定义
提供用于将一个成员与另一个成员相关的基类。Provides the base class for relating one member to another.
public ref class MemberRelationshipService abstract
public abstract class MemberRelationshipService
type MemberRelationshipService = class
Public MustInherit Class MemberRelationshipService
- 继承
-
MemberRelationshipService
示例
MemberRelationshipService简化了从另一个位置检索属性值的情况。The MemberRelationshipService simplifies retrieval of a property value from another location. 设计器可以访问此服务,以指示为一个成员分配了另一个成员的值。A designer can access this service to dictate that one member is assigned the value of another. 代码生成器会在生成代码时搜索此类关系,如果找到两个成员之间的关系,则会发出关系的代码,而不是搜索属性值。The code generator searches for such relationships when generating code, and if a relationship between two members is found the code generator, it emits code for the relationship rather than searching for the property value. 下面的代码示例使用以前的文本赋值作为示例,演示了用于建立关系的设计时代码。Using the previous text assignment as an example, the following code example shows design time code used to establish a relationship.
object titleLabel, form;
PropertyDescriptor titleLabelText = TypeDescriptor.GetProperties(titleLabel)["Text"];
PropertyDescriptor formText = TypeDescriptor.GetProperties(form)["Text"];
MemberRelationshipService ms = GetService(typeof(MemberRelationshipService);
ms[titleLabel, titleLabelText] = new MemberRelationship(form, formText);
注解
设计器通过引擎序列化自己的代码,该引擎可搜索对象的实时属性值并将这些值生成为代码。Designers serialize themselves to code through an engine that searches through the live property values of objects and generates those values as code. 例如,使用以下格式生成按钮的文本。So, for example, the text of a button is generated in the following format.
this.okButton.Text = "OK";
此方案的一项限制是很难从另一个位置检索属性。One of the limitations of this scheme is that it is difficult to retrieve a property from another location. 例如,如果代码生成器可以依赖的唯一内容是属性中的值,则很难用以下格式发出代码。For example, it is very difficult to emit code in the following format, because the only thing the code generator can rely on is the value in the property.
this.titleLabel.Text = this.Text;
实施者说明
MemberRelationshipService类为 abstract 。The MemberRelationshipService class is abstract. 实现具体版本会因受支持的成员类型的不同而不同。Implementing a concrete version varies depending on the types of members that are supported. 例如,将一个事件与另一个事件相关可能需要不同于将一个属性与另一个属性关联的实现。For example, relating one event to another might require a different implementation than relating one property to another. 实现服务需要执行以下步骤:Implementing the service requires the following steps:
-实现 SupportsRelationship(MemberRelationship, MemberRelationship) 以便 true 为你支持的关系返回。- Implement SupportsRelationship(MemberRelationship, MemberRelationship) to return true for relationships that you support.
-跟踪源关系的更改,并将值更改分配给目标关系。- Track changes to the source relationship and assign value changes into the target relationship.
构造函数
| MemberRelationshipService() |
初始化 MemberRelationshipService 类的新实例。Initializes a new instance of the MemberRelationshipService class. |
属性
| Item[MemberRelationship] |
建立源对象与目标对象之间的关系。Establishes a relationship between a source and target object. |
| Item[Object, MemberDescriptor] |
建立源对象与目标对象之间的关系。Establishes a relationship between a source and target object. |
方法
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetRelationship(MemberRelationship) |
获取到给定源关系的关系。Gets a relationship to the given source relationship. |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| SetRelationship(MemberRelationship, MemberRelationship) |
在源对象和目标关系之间创建关系。Creates a relationship between the source object and target relationship. |
| SupportsRelationship(MemberRelationship, MemberRelationship) |
获取一个值,指示是否支持给定关系。Gets a value indicating whether the given relationship is supported. |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |