AddRule 類別
表示規則,將在模型中加入物件時會呼叫此規則。
繼承階層架構
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 | 取得或設定是否已啟用規則。通常預設為 true,但您可以在 RuleOn 屬性中將它初始化為 false。 (繼承自 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 的淺層複本 (Shallow Copy)。 (繼承自 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;
}
}
}
執行緒安全
這個類型的任何 Public static (在 Visual Basic 中為 Shared) 成員都是安全執行緒。不保證任何執行個體成員是安全執行緒。
請參閱
參考
Microsoft.VisualStudio.Modeling 命名空間