If 类

定义

为 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,则true活动执行 。 如果条件解析为 Else,则false活动执行 。

Constraints

获取可配置为提供验证的活动Constraint集合Activity

(继承自 Activity)
DisplayName

获取或设置用于调试、验证、异常处理和跟踪的可选友好名称。

(继承自 Activity)
Else

活动 Condition 解析为 false时要执行的活动。

Id

获取工作流定义范围中唯一的标识符。

(继承自 Activity)
Implementation

活动的执行逻辑。

(继承自 NativeActivity)
ImplementationVersion

获取或设置活动的实现版本。

(继承自 NativeActivity)
Then

活动 Condition 解析为 true时要执行的活动。

方法

名称 说明
Abort(NativeActivityAbortContext)

在派生类中实现时,对中止的活动执行操作。

(继承自 NativeActivity)
CacheMetadata(ActivityMetadata)

未实现。 请改用该方法 CacheMetadata(NativeActivityMetadata)

(继承自 NativeActivity)
CacheMetadata(NativeActivityMetadata)

创建并验证活动参数、变量、子活动和活动委托的说明。

(继承自 NativeActivity)
Cancel(NativeActivityContext)

在派生类中实现时,运行逻辑以正常提前完成活动。

(继承自 NativeActivity)
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
Execute(NativeActivityContext)

在派生类中实现时,运行活动的执行逻辑。

(继承自 NativeActivity)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
OnCreateDynamicUpdateMap(NativeActivityUpdateMapMetadata, Activity)

为动态更新创建映射时引发事件。

(继承自 NativeActivity)
OnCreateDynamicUpdateMap(UpdateMapMetadata, Activity)

为动态更新创建映射时引发事件。

(继承自 NativeActivity)
ShouldSerializeDisplayName()

指示是否 DisplayName 应序列化属性。

(继承自 Activity)
ToString()

返回一个String包含IdDisplayName //Activity

(继承自 Activity)
UpdateInstance(NativeActivityUpdateContext)

更新 . 的 NativeActivity实例。

(继承自 NativeActivity)

适用于