If 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建 If 类的新实例。
重载
If() |
创建 If 类的新实例。 |
If(Activity<Boolean>) |
使用指定的条件创建 If 类的新实例。 |
If(InArgument<Boolean>) |
使用指定的条件创建 If 类的新实例。 |
If(Expression<Func<ActivityContext,Boolean>>) |
使用指定的条件创建 If 类的新实例。 |
If()
创建 If 类的新实例。
public:
If();
public If ();
Public Sub New ()
示例
下面的代码示例演示如何创建 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(Activity<Boolean>)
使用指定的条件创建 If 类的新实例。
public:
If(System::Activities::Activity<bool> ^ condition);
public If (System.Activities.Activity<bool> condition);
new System.Activities.Statements.If : System.Activities.Activity<bool> -> System.Activities.Statements.If
Public Sub New (condition As Activity(Of Boolean))
参数
示例
下面的代码示例演示如何创建 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(InArgument<Boolean>)
使用指定的条件创建 If 类的新实例。
public:
If(System::Activities::InArgument<bool> ^ condition);
public If (System.Activities.InArgument<bool> condition);
new System.Activities.Statements.If : System.Activities.InArgument<bool> -> System.Activities.Statements.If
Public Sub New (condition As InArgument(Of Boolean))
参数
- condition
- InArgument<Boolean>
执行条件。
示例
下面的代码示例演示如何创建 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(Expression<Func<ActivityContext,Boolean>>)
使用指定的条件创建 If 类的新实例。
public:
If(System::Linq::Expressions::Expression<Func<System::Activities::ActivityContext ^, bool> ^> ^ condition);
public If (System.Linq.Expressions.Expression<Func<System.Activities.ActivityContext,bool>> condition);
new System.Activities.Statements.If : System.Linq.Expressions.Expression<Func<System.Activities.ActivityContext, bool>> -> System.Activities.Statements.If
Public Sub New (condition As Expression(Of Func(Of ActivityContext, Boolean)))
参数
- condition
- Expression<Func<ActivityContext,Boolean>>
执行条件。
示例
下面的代码示例演示如何创建 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.")
)))
}
}