zoukankan      html  css  js  c++  java
  • 数据的传递 变量与参数的使用

    数据的传递 变量与参数的使用

    [参数] 可以用 [表达式方式] 与 [变量]绑定

    [In 参数],关联变量值可传入内部;内部修改参数时,关联变量不会更改

    说明:

    1.定义一个[InChangeActivity],有一个string型[In 参数]myIn在[Execute]方法中打印myIn的值并修改myIn的值后再次打印

    2.在xaml工作流中添加一个string型[myVariable]变量

    3. 在xaml工作流中添加一个[Assign],为[myVariable]变量赋值

    4. 在xaml工作流中添加[InChangeActivity], [InChangeActivity.myIn]绑定到[myVariable]变量

    5. 在xaml工作流中添加[WriteLine],打印[myVariable]变量值

    public sealed class InChangeActivity : CodeActivity
        {
            // 定义一个字符串类型的活动输入参数
            public InArgument<string> myIn { get; set; }
    
            // 如果活动返回值,则从 CodeActivity<TResult>
            // 派生并从 Execute 方法返回该值。
            protected override void Execute(CodeActivityContext context)
            {
                // 获取 Text 输入参数的运行时值
                string s1 = context.GetValue(this.myIn);
                System.Console.WriteLine("Input Value is:{0}", s1);
    
                context.SetValue(myIn, Guid.NewGuid().ToString());
    
                string s2 = context.GetValue(this.myIn);
                System.Console.WriteLine("Modify internal:{0}", s2); 
            }
        }

    宿主

    static void Main(string[] args)
            {
                WorkflowInvoker.Invoke(new InChangeWorkflow());
            }

    结果

    [Out 参数] 关联变量值无法传入内部,内部参数修改时,会更新其关联的变量

    说明:

    1.定义一个[OutChangeActivity],有一个string型[Out 参数]myOut在[Execute]方法中打印myOut的值并修改myOut的值后再次打印

    2.在xaml工作流中添加一个string型[myVariable]变量

    3. 在xaml工作流中添加一个[Assign],为[myVariable]变量赋值

    4. 在xaml工作流中添加[OutChangeActivity], [OutChangeActivity.myOut]绑定到[myVariable]变量

    5. 在xaml工作流中添加[WriteLine],打印[myVariable]变量值

    public sealed class OutChangeActivity : CodeActivity
        {
            public OutArgument<string> myOut { get; set; }
    
            // 如果活动返回值,则从 CodeActivity<TResult>
            // 派生并从 Execute 方法返回该值。
            protected override void Execute(CodeActivityContext context)
            {
                string s1 = context.GetValue(this.myOut);
                System.Console.WriteLine("Input Value:{0}", s1);
    
                // 
                context.SetValue(myOut, Guid.NewGuid().ToString());
    
                // 
                string s2 = context.GetValue(this.myOut);
                System.Console.WriteLine("Modify internal:{0}", s2); 
            }
        }

    宿主

    static void Main(string[] args)
            {
                WorkflowInvoker.Invoke(new OutChangeWorkflow());
            }

    结果

    [In/Out 参数]关联变量值可传入内部;内部参数修改时,会更新其关联的变量

    说明:

    1.定义一个 [InOutChangeActivity],有一个string型[InOut 参数]myInOut在[Execute]方法中打印myInOut的值并修改myInOut的值后再次打印

    2.在xaml工作流中添加一个string型[myVariable]变量

    3. 在xaml工作流中添加一个[Assign],为[myVariable]变量赋值

    4. 在xaml工作流中添加[InOutChangeActivity], [InOutChangeActivity.myInOut]绑定到[myVariable]变量

    5. 在xaml工作流中添加[WriteLine],打印[myVariable]变量值

    public sealed class InOutChangeActivity : CodeActivity
        {
            public InOutArgument<string> myInOut { get; set; }
    
            // 如果活动返回值,则从 CodeActivity<TResult>
            // 派生并从 Execute 方法返回该值。
            protected override void Execute(CodeActivityContext context)
            {
                string s1 = context.GetValue(this.myInOut);
                System.Console.WriteLine("Input Value:{0}", s1);
    
                // 
                context.SetValue(myInOut, Guid.NewGuid().ToString());
    
                // 
                string s2 = context.GetValue(this.myInOut);
                System.Console.WriteLine("Modify internal:{0}", s2); 
            }
        }

    宿主

    static void Main(string[] args)
            {
                WorkflowInvoker.Invoke(new InOutChangeWorkflow());
            }

    结果

    参考:http://tech.ddvip.com/2009-11/1259285719139913.html

  • 相关阅读:
    如何对抗信息茧房?
    术语
    2021.07.17软件更新公告
    【C#】C#中使用GDAL3(二):Windows下读写Shape文件及超详细解决中文乱码问题
    【C#】C#中使用GDAL3(一):Windows下超详细编译C#版GDAL3.3.0(VS2015+.NET 4+32位/64位)
    k8s使用私有镜像仓库
    四、Abp vNext 基础篇丨领域构建
    Abp vNext 番外篇-疑难杂症丨认证授权
    三、Abp vNext 基础篇丨分层架构
    知识全聚集 .Net Core 目录篇
  • 原文地址:https://www.cnblogs.com/vincentDr/p/3342871.html
Copyright © 2011-2022 走看看