表示规则,其在对象添加至模型时调用。
继承层次结构
System.Object
Microsoft.VisualStudio.Modeling.Rule
Microsoft.VisualStudio.Modeling.AddRule
Microsoft.VisualStudio.Modeling.Diagrams.CommentShapeAddRule
Microsoft.VisualStudio.Modeling.Diagrams.NodeShape.ExpandCollapseNodeShapeWhenAddedToDiagramRule
Microsoft.VisualStudio.Modeling.Diagrams.ParentShapeContainsNestedChildShapesAddRule
Microsoft.VisualStudio.Modeling.Diagrams.ParentShapeHasRelativeChildShapesAddRule
Microsoft.VisualStudio.Modeling.Diagrams.ShapeElementAddRule
Microsoft.VisualStudio.Modeling.ElementDeserializedRule
命名空间: Microsoft.VisualStudio.Modeling
程序集: Microsoft.VisualStudio.Modeling.Sdk.12.0(在 Microsoft.VisualStudio.Modeling.Sdk.12.0.dll 中)
语法
声明
Public MustInherit Class AddRule _
Inherits Rule
public abstract class AddRule : Rule
AddRule 类型公开以下成员。
构造函数
名称 | 说明 | |
---|---|---|
![]() |
AddRule | 初始化 AddRule 类的实例。 |
页首
属性
名称 | 说明 | |
---|---|---|
![]() |
FireBefore | 如果在更改之前发生执行此规则,则为 true。 (继承自 Rule。) |
![]() |
FireImmediately | 如果此规则立即执行发生的更改,则为 true。 (继承自 Rule。) |
![]() |
FireOnLocalCommit | 如果将在提交当前事务时执行此规则,则为 true。 (继承自 Rule。) |
![]() |
FireOnTopLevelCommit | 如果将在提交顶级事务时执行此规则,则为 true。 (继承自 Rule。) |
![]() |
FireTime | 获取或设置应执行规则的时间。通常由 RuleOn 属性设置。 (继承自 Rule。) |
![]() |
IsEnabled | 获取或设置是否启用规则。通常情况下默认为真,但是您能初始化其至 RuleOn 特性下为假。 (继承自 Rule。) |
![]() |
Priority | 获取分配给规则的优先级别。要确定在事务末尾处执行的规则的顺序的帮助器。 (继承自 Rule。) |
页首
方法
名称 | 说明 | |
---|---|---|
![]() |
CompareTo(Object) | 与另一个对象比较该规则。 (继承自 Rule。) |
![]() |
CompareTo(Rule) | 通过其 ID 与另一个规则比较该规则。 (继承自 Rule。) |
![]() |
ElementAdded | 使用了警报侦听器规则。 |
![]() |
Equals(Object) | 验证该规则是否等于另一对象。 (继承自 Rule。) |
![]() |
Equals(Rule) | 验证规则是否等于另一规则。 (继承自 Rule。) |
![]() |
Finalize | 允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 Object。) |
![]() |
GetHashCode | 获取规则的哈希代码。 (继承自 Rule。) |
![]() |
GetType | 获取当前实例的 Type。 (继承自 Object。) |
![]() |
MemberwiseClone | 创建当前 Object 的浅表副本。 (继承自 Object。) |
![]() |
ToString | 返回表示当前对象的字符串。 (继承自 Object。) |
页首
备注
当元素、关系、连接器、形状或关系图添加到模型中时,此类型规则触发器。
在类上的 RuleOnAttribute 特性 (指明类型的对象有效规则,并且,当规则时应激发。
调用规则,指定类型的对象添加到模型中时,是否在 UI 添加或编程方式。
当元素从文件时,加载规则还触发器。 如果要避免,响应发生这种情况,其中包括在 ElementAdded 的以下代码:
// Ignore this call if we're currently loading a model:
if (e.ModelElement.Store.TransactionManager
.CurrentTransaction.IsSerializing)
return;
有关更多信息和示例,请参见规则在模型内部传播更改。
示例
在下面的示例中,从 AddRule派生了规则定义。 此规则集形状的位置,从而使添加到关系图。
RuleOn 特性指示规则时应激发顶级事务提交。
[RuleOn(typeof(ParentShapeContainsNestedChildShapes), FireTime = TimeToFire.TopLevelCommit)]
public class ShapeAddedToDiagramRule : AddRule
{
private double offset = 0.25;
private PointD ___location = new PointD(0.25, 0.25);
public override void ElementAdded(ElementAddedEventArgs e)
{
Shape shape = null;
ParentShapeContainsNestedChildShapes nestedLink = e.ModelElement as ParentShapeContainsNestedChildShapes;
if (nestedLink != null)
{
shape = nestedLink.NestedChildShapes as Shape;
}
if (shape != null && shape.Diagram != null)
{
// Expand the shape and move it to its new position
shape.IsExpanded = true;
shape.Location = new PointD(___location.X, ___location.Y + offset);
// Adjust the height offset for the size of the shape
// (I'm assuming that the DefaultContainerMargin
// provides for a decent spacing between the shapes)
offset += shape.Size.Height + shape.Diagram.DefaultContainerMargin.Height;
}
}
}
线程安全
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
请参阅
参考
Microsoft.VisualStudio.Modeling 命名空间