小编sse*_*hev的帖子

WF 4.5.使用带外部类引用的C#表达式

我正在尝试使用新的WF 4.5功能 - C#表达式编译动态活动.它一直有效,直到我在表达式中添加外部类.

如果表达式包含基本对象,则表示已编译.如果我添加对外部类的引用,则会生成错误"无法找到类型或命名空间名称'xxxxx'(您是否缺少using指令或程序集引用?)"

那么,问题是我如何引用C#表达式的外部类?

PS它适用于VisualBasic表达式类型

谢谢

//Compiled without errors
var errorCodeWorkflow = new DynamicActivity
{
    Name = "DynamicActivity",
    Implementation = () => new WriteLine
    {
        Text = new CSharpValue<String>
        {
            ExpressionText = "new Random().Next(1, 101).ToString()"
        }
     }
};

CompileExpressions(errorCodeWorkflow);
WorkflowInvoker.Invoke(errorCodeWorkflow);


//Error 

using System;
using System.Activities;
using System.Activities.Expressions;
using System.Activities.Statements;
using System.Activities.XamlIntegration;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CSharp.Activities;

namespace CSharpExpression 
{
    class Program
    {
        static void Main()
        {
            var errorCodeWorkflow = new DynamicActivity
            {
                Name = "MyScenario.MyDynamicActivity3",
                Properties = …
Run Code Online (Sandbox Code Playgroud)

c# workflow-foundation

3
推荐指数
1
解决办法
3226
查看次数

标签 统计

c# ×1

workflow-foundation ×1