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.")
)))
}
}
构造函数
| 名称 | 说明 |
|---|---|
| If() |
创建类的新实例 If 。 |
| If(Activity<Boolean>) |
使用指定的条件创建类的新实例 If 。 |
| If(Expression<Func<ActivityContext,Boolean>>) |
使用指定的条件创建类的新实例 If 。 |
| If(InArgument<Boolean>) |
使用指定的条件创建类的新实例 If 。 |
属性
| 名称 | 说明 |
|---|---|
| CacheId |
获取在工作流定义范围内唯一的缓存的标识符。 (继承自 Activity) |
| CanInduceIdle |
获取或设置一个值,该值指示活动是否可能导致工作流处于空闲状态。 (继承自 NativeActivity) |
| Condition |
确定要执行的子活动的条件。 如果条件解析为 Then,则 |
| Constraints |
获取可配置为提供验证的活动Constraint集合Activity。 (继承自 Activity) |
| DisplayName |
获取或设置用于调试、验证、异常处理和跟踪的可选友好名称。 (继承自 Activity) |
| Else |
活动 Condition 解析为 |
| Id |
获取工作流定义范围中唯一的标识符。 (继承自 Activity) |
| Implementation |
活动的执行逻辑。 (继承自 NativeActivity) |
| ImplementationVersion |
获取或设置活动的实现版本。 (继承自 NativeActivity) |
| Then |
活动 Condition 解析为 |