If 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建模一個 If-Then-Else 條件。
public ref class If sealed : System::Activities::NativeActivity
public sealed class If : System.Activities.NativeActivity
type If = class
inherit NativeActivity
Public NotInheritable Class If
Inherits NativeActivity
- 繼承
範例
以下程式碼範例示範建立一項 If 活動。
new If
{
// check if the order is asking for Widgets
Condition = new InArgument<bool>( (e) => po.Get(e).PartName.Equals("Widget") ),
Then = new If
{
// check if we have enough widgets in stock
Condition = new InArgument<bool>( (e) => po.Get(e).Quantity < 100 ),
Then = new SendReply
{
DisplayName = "Successful response",
Request = submitPO,
Content = SendContent.Create(new InArgument<string>( (e) => string.Format("Success: {0} Widgets have been ordered!", po.Get(e).Quantity)) )
},
// if we don't have enough widgets, throw an unhandled exception from this operation's body
Else = new Throw
{
Exception = new InArgument<Exception>((e) => new Exception("We don't have that many Widgets."))
}
},
// if its not for widgets, reply to the client that we don't carry that part by sending back an expected fault type (POFault)
Else = new SendReply
{
DisplayName = "Expected fault",
Request = submitPO,
Content = SendContent.Create(new InArgument<FaultException<POFault>>( (e) => new FaultException<POFault>(
new POFault
{
Problem = string.Format("This company does not carry {0}s, but we do carry Widgets.", po.Get(e).PartName),
Solution = "Try your local hardware store."
},
new FaultReason("This is an expected fault.")
)))
}
}
建構函式
| 名稱 | Description |
|---|---|
| If() |
建立一個新的類別實例 If 。 |
| If(Activity<Boolean>) |
使用指定條件建立該類別的新實例 If 。 |
| If(Expression<Func<ActivityContext,Boolean>>) |
使用指定條件建立該類別的新實例 If 。 |
| If(InArgument<Boolean>) |
使用指定條件建立該類別的新實例 If 。 |
屬性
| 名稱 | Description |
|---|---|
| CacheId |
取得在工作流程定義範圍內唯一且快取識別碼的識別碼。 (繼承來源 Activity) |
| CanInduceIdle |
取得或設定一個值,指示該活動是否會導致工作流程進入閒置狀態。 (繼承來源 NativeActivity) |
| Condition |
決定執行哪個子活動的條件。
Then若條件解決為 |
| Constraints |
取得一組 Constraint 可設定以驗證 的 Activity活動集合。 (繼承來源 Activity) |
| DisplayName |
取得或設定一個可選的友善名稱,用於除錯、驗證、異常處理及追蹤。 (繼承來源 Activity) |
| Else |
若該活動 Condition 的解析為 |
| Id |
取得一個在工作流程定義範圍內唯一的識別碼。 (繼承來源 Activity) |
| Implementation |
活動的執行邏輯。 (繼承來源 NativeActivity) |
| ImplementationVersion |
取得或設定活動的實作版本。 (繼承來源 NativeActivity) |
| Then |
若該活動 Condition 的解析為 |