Class Component
Represents component in the diagram model. Requires component name, parent component and valid children component types. Holds info about children components, allows their filtration based on provided type and offers interface for their manipulation (namely for adding and deleting certain children components).
Inheritance
Inherited Members
Namespace: DiagramModel.Components
Assembly: cs.temp.dll.dll
Syntax
public abstract class Component
Constructors
Component(String, Component, ICollection<String>)
Declaration
public Component(string name, Component parent, ICollection<string> validChildren)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | |
| Component | parent | |
| ICollection<System.String> | validChildren |
Fields
children
Declaration
protected readonly List<Component> children
Field Value
| Type | Description |
|---|---|
| List<Component> |
Properties
Children
Collection of component's children. Each of these children has this component set as Parent to allow bidirectional component tree traversing.
Declaration
public IReadOnlyList<Component> Children { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<Component> |
Name
Represents component name. Could be interpreted also as component value based on the context. It is specified explicitly for each component as component constructor requires name parameter.
Declaration
public virtual string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
Parent
Parent component this component belongs to. Represents component layers using tree structure where root component is Diagram.
Declaration
public Component Parent { get; protected set; }
Property Value
| Type | Description |
|---|---|
| Component |
UniqueTypeName
Holds unique name of the component. Must be 1-word only to preserve correct command parsing.
Declaration
public abstract string UniqueTypeName { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
ValidChildrenTypes
Returns collection of valid children component typenames.
Declaration
public ICollection<string> ValidChildrenTypes { get; }
Property Value
| Type | Description |
|---|---|
| ICollection<System.String> |
Methods
AddChild(Component)
Appends new component child. Does not check if the child has valid type for this component. Check needs to be performed before this method is called.
Declaration
public virtual void AddChild(Component child)
Parameters
| Type | Name | Description |
|---|---|---|
| Component | child | Validated component child to add. |
Clone()
Performs deep copy of the component. It is useful mainly for command execution phase. During this phase, commands are executed one by one which modifies component tree. If an error occurrs while executing one of the commands, we need to revert back all changes made. For that, we can use the previously created deep copy of the whole component tree.
Declaration
public abstract Component Clone()
Returns
| Type | Description |
|---|---|
| Component |
CloneChildrenInto(Component)
Inserts deep copy of this component's children into parent component which is provided as a parameter.
Declaration
protected void CloneChildrenInto(Component parent)
Parameters
| Type | Name | Description |
|---|---|---|
| Component | parent |
FindChild(String, String)
Searches for child component based on its typename and child component name.
Declaration
public virtual Component FindChild(string childType, string childName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | childType | For valid values see UniqueTypeName |
| System.String | childName | Corresponds to the Name |
Returns
| Type | Description |
|---|---|
| Component | Searched child component or null if no matching component was found. |
GetTypeFilteredChildren<T>()
Filters children components that match the given type.
Declaration
protected List<T> GetTypeFilteredChildren<T>()
where T : Component
Returns
| Type | Description |
|---|---|
| List<T> | Collection of child components of the provided type. |
Type Parameters
| Name | Description |
|---|---|
| T | Component type to filter. |
GetUniqueChild<T>()
Gets child component matching the provided type. Relies on child being unique for this component, such as Visibility or Type.
Declaration
protected T GetUniqueChild<T>()
where T : Component
Returns
| Type | Description |
|---|---|
| T | Child component or null if no component of the matching type exists. |
Type Parameters
| Name | Description |
|---|---|
| T | Child component type. |
TryDeleteChild(String, String)
Tries to delete child based on its typename and child component name.
Declaration
public virtual bool TryDeleteChild(string childType, string childName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | childType | For valid values see UniqueTypeName |
| System.String | childName | Corresponds to the Name |
Returns
| Type | Description |
|---|---|
| System.Boolean | Result of the delete operation. |