Jav*_*der 5 workflowservice workflow-foundation-4 c#-4.0
I have an Activity where I declared a InArgument without a type (because I want to know the type of the Expression at design time).
When I execute the activity I get this error in var contentTelegram line:
"The argument of type '<type>' cannot be used. Make sure that it is declared on an activity."
Run Code Online (Sandbox Code Playgroud)
Here is my code:
public InArgument Content { get; set; }
protected override PlcMessage Execute(CodeActivityContext context)
{
try
{
var contentTelegram = Content.Get(context);
return new PlcMessage();
}
catch (Exception ex)
{
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我所做的:
工作流运行时需要了解参数中使用的类型,因此 CacheMetadata 是使其工作的关键,CacheMetadata 使用反射来了解参数,请注意,这只适用于简单的情况。
public sealed class MyActivity: CodeActivity
{
private RuntimeArgument outMyRuntimeArgument;
// Define an activity input argument of type string
public OutArgument MyUntypedArgument { get; set; }
protected override void CacheMetadata(CodeActivityMetadata metadata)
{
outMyArgument= new RuntimeArgument("MyUntypedArgument", MyUntypedArgument.ArgumentType, ArgumentDirection.Out);
metadata.Bind(MyUntypedArgument, outArgument);
metadata.AddArgument(outMyArgument);
}
protected override void Execute(CodeActivityContext context)
{
context.SetValue(outMyRuntimeArgument, Activator.CreateInstance(Type));
}
}
Run Code Online (Sandbox Code Playgroud)