5

我在Visual Studio 11 Beta中创建了一个活动库(尽管我已经在VS2010中重复了所有步骤,结果相同),面向.NET 4.0框架。在工作流设计器中从VB切换到C#

当我开始通过工作流设计进入论据,我注意到在默认值中的“输入VB表达式”的消息。我不确定如何将语言上下文从VB更改为C#。

要创建项目,我按照这些步骤:

  1. 转到文件>并选择项目...

  2. 在安装了>新建项目对话窗口的部分模板,选择Visual C#>工作流程>活动库

  3. 名称的项目,像往常一样,并单击OK

而这基本上它。然后我注意到,缺省值Activity1.xaml文件在默认值字段中预期VB。我删除它,然后按照这些步骤来创建一个新的活动:

  1. 在项目上右键单击,然后选择添加>新项...

  2. 在添加新项对话窗口,导航到安装>的Visual C#项目>工作流>活动

  3. 名称的活动,然后单击确定

这是相同的结果,默认值字段都期待一个VB表达。

当我查看XAML代码时,我可以清楚地看到Microsoft.VisualBasic.Activities命名空间列表和VisualBasic.Settings元素,但我不知道如何改变它;每次我尝试,我最终都会搞砸了。这里是正在生成的XAML代码:

<Activity mc:Ignorable="sads sap" x:Class="THINKImport.CustomerAddOrderAdd" 
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" 
xmlns:local="clr-namespace:THINKImport.THINKWebReference" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" 
xmlns:s="clr-namespace:System;assembly=System.Core" 
xmlns:s1="clr-namespace:System;assembly=System" 
xmlns:s2="clr-namespace:System;assembly=System.ServiceModel" 
xmlns:s3="clr-namespace:System;assembly=mscorlib" 
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger" 
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" 
xmlns:t="clr-namespace:THINKImport" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
<x:Members> 
    <x:Property Name="user_login_data" Type="InArgument(local:user_login_data)" /> 
    <!--Removed the other properties for brevity--> 
    </x:Members> 
    <sap:VirtualizedContainerService.HintSize>440,440</sap:VirtualizedContainerService.HintSize> 
    <mva:VisualBasic.Settings>Assembly references and imported namespaces for internal implementation</mva:VisualBasic.Settings> 
</Activity> 

回答

5

C#表达式

此前,在工作流程的所有表情只能用Visual 基础。在.NET Framework 4.5 RC中,Visual Basic表达式仅用于使用Visual Basic创建的项目的 。 Visual C#项目现为 使用C#表达式。一个功能齐全的C#表达式编辑器是 ,提供了诸如语法高亮和智能感知等功能。以前版本中使用Visual Basic表达式创建的C#工作流程项目将继续工作。

从Beta 1开始,C#表达式将在设计时验证。 中的错误C#表达式将以红色波浪下划线标记。

更多:What's New in Windows Workflow Foundation in .NET 4.5

5

我能找出问题。

首先,我能够发现根本原因here。简而言之,它说VB.NET必须在Expression Editor中使用,即使程序是用C#编写的。

所以,我是有点郁闷这件事,但我决定采取另一种裂纹在XAML代码,因为,在通过WF辅导工作,还有最绝的一个活动,我在会接受表达式设计工作在C#中。我打开了该项目,并通过了XAML代码。

它当时我才注意到这行:

​​

我搜索MSDN库,发现documentation for the ExpressionActivityEditor class。尽我所知,这是.NET 4.5的新功能。在我的特殊情况下,没有任何理由不能在我的项目中使用.NET 4.5,所以我改变了它。一旦解决方案重新打开,所有Expression Editor文本字段和框都将接受C#。为了“开始新鲜”,我删除了我一直在处理的活动文件并创建了一个新文件。如果任何人的兴趣,这里的生成XAML代码:

<Activity mc:Ignorable="sap sap2010 sads" x:Class="THINKImport.CustomerAddOrderAdd" 
     xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger" 
     xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" 
     xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation" 
     xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:THINKWebReference="clr-namespace:THINKImport.THINKWebReference"> 
    <x:Members> 
    <x:Property Name="user_login_data" Type="InArgument(THINKWebReference:user_login_data)"> 
    <x:Property.Attributes> 
     <RequiredArgumentAttribute /> 
     </x:Property.Attributes> 
    </x:Property> 
    <x:Property Name="customer_data" Type="InArgument(THINKWebReference:customer_data)" /> 
    <!--Remainder of Properties removed for brevity--> 
    </x:Members> 
    <sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor> 
    <TextExpression.NamespacesForImplementation> 
    <sco:Collection x:TypeArguments="x:String"> 
     <x:String>System</x:String> 
     <x:String>System.Collections.Generic</x:String> 
     <x:String>System.Data</x:String> 
     <x:String>System.Linq</x:String> 
     <x:String>System.Text</x:String> 
    </sco:Collection> 
    </TextExpression.NamespacesForImplementation> 
    <TextExpression.ReferencesForImplementation> 
    <sco:Collection x:TypeArguments="AssemblyReference"> 
     <AssemblyReference>mscorlib</AssemblyReference> 
     <AssemblyReference>System</AssemblyReference> 
     <AssemblyReference>System.Core</AssemblyReference> 
     <AssemblyReference>System.Data</AssemblyReference> 
     <AssemblyReference>System.ServiceModel</AssemblyReference> 
     <AssemblyReference>System.Xml</AssemblyReference> 
    </sco:Collection> 
    </TextExpression.ReferencesForImplementation> 
    <sap2010:WorkflowViewState.IdRef> 
    THINKImport.CustomerAddOrderAdd_1 
    </sap2010:WorkflowViewState.IdRef> 
    <sap2010:WorkflowViewState.ViewStateManager> 
    <sap2010:ViewStateManager> 
     <sap2010:ViewStateData Id="THINKImport.CustomerAddOrderAdd_1" sap:VirtualizedContainerService.HintSize="440,440" /> 
    </sap2010:ViewStateManager> 
    </sap2010:WorkflowViewState.ViewStateManager> 
</Activity> 

因此,相当多的不同(对我来说,反正),但我可以使用C#现在,所以我很高兴。

相关问题