1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.Statements;
using Microsoft.VisualBasic.Activities;
namespace Test3
{
public class MyCodeWorkflow
{
public Activity GetActivity()
{
Activity activity = new Sequence()
{
Variables ={
new Variable <double>("resultat",0.0),
new Variable <string>("Sresultat",""),
new Variable <string>("operateur","")
},
Activities ={
new WriteLine{Text ="Nombre?"},
new InvokeMethod {TargetType=typeof(System.Console),MethodName="ReadLine",Result=new OutArgument<string>(new VisualBasicReference<string>("Sresultat"))},
new Assign<double>{To=new OutArgument<double>(new VisualBasicReference<double>("resultat")),Value=new VisualBasicValue<double>("Convert.ToDouble(Sresultat)") },
new WriteLine {Text ="operateur?"},
new InvokeMethod {TargetType=typeof(System.Console),MethodName="ReadLine",Result=new OutArgument<string>(new VisualBasicReference<string>("operateur"))},
new While
{
Condition=new VisualBasicValue<bool>("operateur.Equals(\"=\")=False"),
Body=
new Sequence{
Variables={
new Variable<double>("Nombre",0.0),
new Variable<string>("Snombre","")
},
Activities={
new WriteLine{Text="Nombre?"},
new InvokeMethod{TargetType=typeof(System.Console),MethodName="ReadLine",Result=new OutArgument<string>(new VisualBasicReference<string>("Snombre"))},
new Assign<double>{To=new OutArgument<double>(new VisualBasicReference<double>("resultat")),Value=new VisualBasicValue<double>("Convert.ToDouble(Sresultat)") },
new Switch<string>
{
Expression=new InArgument<string>(new VisualBasicValue<string>("operateur")),
Cases =
{ new KeyValuePair<string,Activity>("+",
new Assign<double>
{To=new OutArgument<double>(new VisualBasicReference<double>("resultat")),
Value=new VisualBasicValue<double>("resultat + nombre")
}
),
new KeyValuePair<string,Activity>("-",
new Assign<double>
{To=new OutArgument<double>(new VisualBasicReference<double>("resultat")),
Value=new VisualBasicValue<double>("resultat - nombre")
}
),
new KeyValuePair<string,Activity>("*",
new Assign<double>
{To=new OutArgument<double>(new VisualBasicReference<double>("resultat")),
Value=new VisualBasicValue<double>("resultat * nombre")
}
),
new KeyValuePair<string,Activity>("/",
new TryCatch{
Try= new Assign<double>
{To=new OutArgument<double>(new VisualBasicReference<double>("resultat")),
Value=new VisualBasicValue<double>("resultat + nombre")
},
Catches={
new Catch<DivideByZeroException>
{
}
}
}//trycatch
)
},//cases
Default =
{
}
},//switch
new WriteLine { Text="operateur?"},
new InvokeMethod {TargetType=typeof(System.Console),MethodName="ReadLine",Result=new OutArgument<string>(new VisualBasicReference<string>("operateur"))}
},//activité
}//sequence
},//while
new WriteLine{ Text=new VisualBasicValue<string>("resultat.ToString()")},
}//Activities
};//activity
return (activity);
}//Getactivity
}
} |
Partager