Welcome

首页 / 软件开发 / .NET编程技术 / WF4.0 - RC相对于Beta2的变化

WF4.0 - RC相对于Beta2的变化2011-08-04 博客园 朱祁林1、RC中的FlowChart使用FlowSwitch<T>代替了FlowSwitch

描述:在Beta2中,活动工具栏上的FlowSwitch将生成一个非泛型FlowSwitch,在RC中生成泛型FlowSwitch<T>,修改的理由是非泛型FlowSwitch只允许string类型的 switch,FlowSwitch<T> 允许任何类型的switch。

用户影响:在Beta2或者更早的版本WF设计器中使用了FlowSwitch创建的Flowchart,将不能在beta2之后的WF设计器中加载。

缓解:在Beta2 中如果你在Flowchart工作流中已经使用了FlowSwitch ,你需要手动的编辑flowchart的XAML,添加 x:TypeArguments="x:String"到FlowSwitch 节点,如下面代码段Beta2:

<FlowSwitch Default="{x:Reference __ReferenceID2}" x:Name="__ReferenceID3" Expression="[variable1]">
<x:Reference>__ReferenceID0<x:Key>Ray</x:Key></x:Reference>
<x:Reference>__ReferenceID1<x:Key>Bill</x:Key></x:Reference>
</FlowSwitch>

RC:

<FlowSwitch x:TypeArguments="x:String" Default="{x:Reference __ReferenceID2}" x:Name="__ReferenceID3" Expression="[variable1]">
<x:Reference>__ReferenceID0<x:Key>Ray</x:Key></x:Reference>
<x:Reference>__ReferenceID1<x:Key>Bill</x:Key></x:Reference>
</FlowSwitch>

2、Literal <T>表达式中的引用的类型

描述:在WF中Literal表达式使用Literal<T>活动表示,在Beta2 中任何类型都能使用这个表达式。在RC中使用引用类型的实例初始化Literal<T> 是无效的。String是唯一的例外。做这种改变的动机是用户错误的认为使用新的引用类型创建一个Literal<T> 要为每一个工作流实例创建新的引用类型。不允许 “Literal”使用引用类型消除这种混乱。在Beta2以下定义的工作流将跑不出错误。 在RC它将收到一个检验错误:

"Literal<List<String>>": Literal only supports value types and the immutable type System.String. The type System.Collections.Generic.List`1[System.String] cannot be used as a literal.

List<string> names = new List<string> {"Frank", "Joe", "Bob" };

Variable<List<string>> nameVar = new Variable<List<string>> { Default = new Literal<List<string>>(names)};
//Note: the following is the equivalent to the line above, the implicit cast creates a Literal<T> expression
//Variable<List<string>> nameVar = new Variable<List<string>> { Default = names };

DelegateInArgument<string> name = new DelegateInArgument<string>();
Activity program = new Sequence
{
Variables = { nameVar },
Activities =
{
new AddToCollection<string> {
Collection = new InArgument<ICollection<string>>(nameVar),
Item = new InArgument<string>("Jim")},
new ForEach<string>{
Values = new InArgument<IEnumerable<string>>(nameVar),
Body = new ActivityAction<string>{
Argument = name,
Handler = new WriteLine { Text = new InArgument<string>(name)}}}
}
};