MemberRelationshipService Class

MemberRelationshipService Class

Provides the base class for relating one member to another.


Namespace:  System.ComponentModel.Design.Serialization
Assembly:  System (in System.dll)

[HostProtectionAttribute(SecurityAction.LinkDemand, SharedState = true)]
public abstract class MemberRelationshipService

The MemberRelationshipService type exposes the following members.

Protected methodMemberRelationshipServiceInitializes a new instance of the MemberRelationshipService class.

Public propertyItem[MemberRelationship]Establishes a relationship between a source and target object.
Public propertyItem[Object, MemberDescriptor]Establishes a relationship between a source and target object.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Protected methodGetRelationshipGets a relationship to the given source relationship.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodSetRelationshipCreates a relationship between the source object and target relationship.
Public methodSupportsRelationshipGets a value indicating whether the given relationship is supported.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

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;

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: SharedState. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

Notes to Inheritors

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:

  • Implement SupportsRelationship to return true for relationships that you support.

  • Track changes to the source relationship and assign value changes into the target relationship.

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);

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

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

Community Additions

© 2016 Microsoft